xenomai.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/copperplate: Release main threadobj on exit
@ 2023-01-10  6:37 Jan Kiszka
  0 siblings, 0 replies; only message in thread
From: Jan Kiszka @ 2023-01-10  6:37 UTC (permalink / raw)
  To: Xenomai; +Cc: Mauro S.

From: Jan Kiszka <jan.kiszka@siemens.com>

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.

Reported-by: Mauro S. <mau.salvi@tin.it>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 lib/copperplate/threadobj.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index f4588a17a8..6808bcf164 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -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;
 }
 
-- 
2.35.3

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-10  6:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-10  6:37 [PATCH] lib/copperplate: Release main threadobj on exit Jan Kiszka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).