* [Xenomai-core] [PATCH] Fix tiny memory leaks around rt_task_self()
@ 2008-04-11 12:51 Jan Kiszka
2008-04-11 13:27 ` Gilles Chanteperdrix
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2008-04-11 12:51 UTC (permalink / raw)
To: Xenomai-core
Nothing critical, but when using rt_task_self != NULL as a hint if the
caller is Xenomai-mapped or not, this stall malloc can become at least
unpleasant. This is also material for stable.
Jan
---
Index: xenomai/ChangeLog
===================================================================
--- xenomai/ChangeLog (Revision 3698)
+++ xenomai/ChangeLog (Arbeitskopie)
@@ -1,3 +1,8 @@
+2008-04-11 Jan Kiszka <jan.kiszka@domain.hid>
+
+ * src/skins/native/task.c: Fix tiny memory leaks of the task's
+ self-reference key.
+
2008-04-10 Philippe Gerum <rpm@xenomai.org>
* src/skins/*: Force minimum stack size to 32k, in order to work
Index: xenomai/src/skins/native/task.c
===================================================================
--- xenomai/src/skins/native/task.c (Revision 3698)
+++ xenomai/src/skins/native/task.c (Arbeitskopie)
@@ -52,6 +52,11 @@ static void rt_task_sigharden(int sig)
XENOMAI_SYSCALL1(__xn_sys_migrate, XENOMAI_XENO_DOMAIN);
}
+static void rt_task_cleanup_tskey(void *arg)
+{
+ free(pthread_getspecific(__native_tskey));
+}
+
static void *rt_task_trampoline(void *cookie)
{
struct rt_task_iargs *iargs = (struct rt_task_iargs *)cookie;
@@ -92,8 +97,11 @@ static void *rt_task_trampoline(void *co
err = XENOMAI_SYSCALL2(__xn_sys_barrier, &entry, &cookie);
while (err == -EINTR);
- if (!err)
+ if (!err) {
+ pthread_cleanup_push(rt_task_cleanup_tskey, NULL);
entry(cookie);
+ pthread_cleanup_pop(1);
+ }
fail:
@@ -294,8 +302,10 @@ RT_TASK *rt_task_self(void)
self = (RT_TASK *)malloc(sizeof(*self));
if (!self ||
- XENOMAI_SKINCALL1(__native_muxid, __native_task_self, self) != 0)
+ XENOMAI_SKINCALL1(__native_muxid, __native_task_self, self) != 0) {
+ free(self);
return NULL;
+ }
pthread_setspecific(__native_tskey, self);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [Xenomai-core] [PATCH] Fix tiny memory leaks around rt_task_self()
2008-04-11 12:51 [Xenomai-core] [PATCH] Fix tiny memory leaks around rt_task_self() Jan Kiszka
@ 2008-04-11 13:27 ` Gilles Chanteperdrix
2008-04-11 14:06 ` Jan Kiszka
0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2008-04-11 13:27 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Xenomai-core
Jan Kiszka wrote:
> Nothing critical, but when using rt_task_self != NULL as a hint if the
> caller is Xenomai-mapped or not, this stall malloc can become at least
> unpleasant. This is also material for stable.
This looks useless: TSD cleanup routines are automatically called
upon thread termination. It is even worse: you risk a double free if you
do not re-set pthread_setspecific after having called free.
--
Gilles.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-core] [PATCH] Fix tiny memory leaks around rt_task_self()
2008-04-11 13:27 ` Gilles Chanteperdrix
@ 2008-04-11 14:06 ` Jan Kiszka
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2008-04-11 14:06 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: Xenomai-core
Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
> > Nothing critical, but when using rt_task_self != NULL as a hint if the
> > caller is Xenomai-mapped or not, this stall malloc can become at least
> > unpleasant. This is also material for stable.
>
> This looks useless: TSD cleanup routines are automatically called
> upon thread termination. It is even worse: you risk a double free if you
> do not re-set pthread_setspecific after having called free.
Ah, I missed the already existing cleanup in init.c. Then we are done
with this patch:
Index: xenomai/ChangeLog
===================================================================
--- xenomai/ChangeLog (Revision 3698)
+++ xenomai/ChangeLog (Arbeitskopie)
@@ -1,3 +1,8 @@
+2008-04-11 Jan Kiszka <jan.kiszka@domain.hid>
+
+ * src/skins/native/task.c (rt_task_self): Fix tiny memory leak
+ when being invoked over a non-Xenomai thread.
+
2008-04-10 Philippe Gerum <rpm@xenomai.org>
* src/skins/*: Force minimum stack size to 32k, in order to work
Index: xenomai/src/skins/native/task.c
===================================================================
--- xenomai/src/skins/native/task.c (Revision 3698)
+++ xenomai/src/skins/native/task.c (Arbeitskopie)
@@ -294,8 +294,10 @@ RT_TASK *rt_task_self(void)
self = (RT_TASK *)malloc(sizeof(*self));
if (!self ||
- XENOMAI_SKINCALL1(__native_muxid, __native_task_self, self) != 0)
+ XENOMAI_SKINCALL1(__native_muxid, __native_task_self, self) != 0) {
+ free(self);
return NULL;
+ }
pthread_setspecific(__native_tskey, self);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-04-11 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-11 12:51 [Xenomai-core] [PATCH] Fix tiny memory leaks around rt_task_self() Jan Kiszka
2008-04-11 13:27 ` Gilles Chanteperdrix
2008-04-11 14:06 ` Jan Kiszka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.