Skip to contentSkip to conversation

lib/copperplate: Release main threadobj on exit

PATCH New Jan Kiszka 1 participant 1 message Jan 10, 2023

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 lib/copperplate: Release main threadobj on exit

From: Jan Kiszka <[email protected]>

In case of CONFIG_XENO_PSHARED, the main thread's tcb is allocated on the shared heap. Normally, threadobjs are released via the destructor of threadobj_tskey. But this is not called when the main thread terminates so that we leak the object. Fix that by installing an atexit handler that only needs to perform the release now.

---
 lib/copperplate/threadobj.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
lib/copperplate/threadobj.c +11 -0
index f4588a17a8..6808bcf164 100644
@@ -1770,6 +1770,13 @@ int threadobj_set_schedprio(struct threadobj *thobj, int priority)
 	return threadobj_set_schedparam(thobj, policy, &param_ex);
 }
 
+#ifdef CONFIG_XENO_PSHARED
+static void main_exit(void)
+{
+	threadobj_free(threadobj_current());
+}
+#endif
+
 static inline int main_overlay(void)
 {
 	struct threadobj_init_data idata;
@@ -1806,6 +1813,10 @@ static inline int main_overlay(void)
 	threadobj_prologue(tcb, NULL);
 	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
 
+#ifdef CONFIG_XENO_PSHARED
+	atexit(main_exit);
+#endif
+
 	return 0;
 }
 
Signature · 1 line
2.35.3