From: Jan Kiszka <jan.kiszka@domain.hid>
To: Philippe Gerum <rpm@xenomai.org>
Cc: xenomai@xenomai.org
Subject: [Xenomai-core] [PATCH v3 8/9] native: Fix memory leak on heap/queue auto-deletion
Date: Tue, 20 Oct 2009 13:37:26 +0200 [thread overview]
Message-ID: <20091020113726.9069.91437.stgit@domain.hid> (raw)
In-Reply-To: <20091020113724.9069.23594.stgit@domain.hid>
We are currently leaking user space heap/queue objects when the owner
terminates without deleting them before. Fix it by releasing the objects
in the corresponding cleanup callbacks which are also called on owner
termination.
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
ksrc/skins/native/heap.c | 5 +++++
ksrc/skins/native/queue.c | 5 +++++
ksrc/skins/native/syscall.c | 25 ++++++-------------------
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/ksrc/skins/native/heap.c b/ksrc/skins/native/heap.c
index f7411e8..886758c 100644
--- a/ksrc/skins/native/heap.c
+++ b/ksrc/skins/native/heap.c
@@ -341,6 +341,11 @@ static void __heap_post_release(struct xnheap *h)
xnpod_schedule();
xnlock_put_irqrestore(&nklock, s);
+
+#ifdef CONFIG_XENO_OPT_PERVASIVE
+ if (heap->cpid)
+ xnfree(heap);
+#endif
}
/**
diff --git a/ksrc/skins/native/queue.c b/ksrc/skins/native/queue.c
index 3592a4a..249947a 100644
--- a/ksrc/skins/native/queue.c
+++ b/ksrc/skins/native/queue.c
@@ -303,6 +303,11 @@ static void __queue_post_release(struct xnheap *heap)
xnpod_schedule();
xnlock_put_irqrestore(&nklock, s);
+
+#ifdef CONFIG_XENO_OPT_PERVASIVE
+ if (q->cpid)
+ xnfree(q);
+#endif
}
/**
diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index 28c720e..cb9f075 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -2073,24 +2073,17 @@ static int __rt_queue_delete(struct pt_regs *regs)
{
RT_QUEUE_PLACEHOLDER ph;
RT_QUEUE *q;
- int err;
if (__xn_safe_copy_from_user(&ph, (void __user *)__xn_reg_arg1(regs),
sizeof(ph)))
return -EFAULT;
q = (RT_QUEUE *)xnregistry_fetch(ph.opaque);
-
if (!q)
- err = -ESRCH;
- else {
- /* Callee will check the queue descriptor for validity again. */
- err = rt_queue_delete_inner(q, (void __user *)ph.mapbase);
- if (!err && q->cpid)
- xnfree(q);
- }
+ return -ESRCH;
- return err;
+ /* Callee will check the queue descriptor for validity again. */
+ return rt_queue_delete_inner(q, (void __user *)ph.mapbase);
}
/*
@@ -2604,7 +2597,6 @@ static int __rt_heap_delete(struct pt_regs *regs)
{
RT_HEAP_PLACEHOLDER ph;
RT_HEAP *heap;
- int err;
if (__xn_safe_copy_from_user(&ph, (void __user *)__xn_reg_arg1(regs),
sizeof(ph)))
@@ -2613,15 +2605,10 @@ static int __rt_heap_delete(struct pt_regs *regs)
heap = (RT_HEAP *)xnregistry_fetch(ph.opaque);
if (!heap)
- err = -ESRCH;
- else {
- /* Callee will check the heap descriptor for validity again. */
- err = rt_heap_delete_inner(heap, (void __user *)ph.mapbase);
- if (!err && heap->cpid)
- xnfree(heap);
- }
+ return -ESRCH;
- return err;
+ /* Callee will check the heap descriptor for validity again. */
+ return rt_heap_delete_inner(heap, (void __user *)ph.mapbase);
}
/*
next prev parent reply other threads:[~2009-10-20 11:37 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-20 11:37 [Xenomai-core] [PATCH v3 0/9] heap setup/cleanup fixes, refactorings & more Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 6/9] rtai: Try to fix _shm_free Jan Kiszka
2009-10-24 17:25 ` Philippe Gerum
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 5/9] nucleus: Avoid returning errors from xnheap_destroy_mapped Jan Kiszka
2009-10-24 17:22 ` Philippe Gerum
2009-11-02 16:04 ` Philippe Gerum
2009-11-02 16:41 ` Jan Kiszka
2009-11-02 16:51 ` Philippe Gerum
2009-11-02 16:57 ` Jan Kiszka
2009-11-02 18:01 ` Jan Kiszka
2009-11-02 18:19 ` [Xenomai-help] Xenomai on ARMadeus Pierre Ficheux
2009-11-02 18:22 ` Gilles Chanteperdrix
2009-11-02 18:38 ` Gilles Chanteperdrix
2009-11-02 19:19 ` gwenhael.goavec
2009-11-02 22:29 ` Gilles Chanteperdrix
2009-11-03 7:36 ` gwenhael.goavec
[not found] ` <20091103082204.248eed59@domain.hid>
2009-11-04 13:14 ` Gilles Chanteperdrix
[not found] ` <fbc4f538a6f4d84cfe514aba0985a525.squirrel@domain.hid>
2009-11-12 14:59 ` Gilles Chanteperdrix
2009-11-02 18:26 ` [Xenomai-core] [PATCH v3 5/9] nucleus: Avoid returning errors from xnheap_destroy_mapped Philippe Gerum
2009-11-03 8:26 ` Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 1/9] native: Release fastlock to the proper heap Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 3/9] nucleus: Fix race window in heap mapping procedure Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 4/9] nucleus: xnheap_destroy does not fail Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 2/9] nucleus: Use Linux spin lock for heap list management Jan Kiszka
2009-10-20 11:37 ` Jan Kiszka [this message]
2009-10-22 10:30 ` [Xenomai-core] [PATCH] native: Avoid double release on queue/heap auto-cleanup Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 7/9] native: Do not requeue on auto-cleanup errors Jan Kiszka
2009-10-20 11:37 ` [Xenomai-core] [PATCH v3 9/9] nucleus: Include all heaps in statistics Jan Kiszka
2009-10-20 23:41 ` Philippe Gerum
2009-10-22 10:52 ` Jan Kiszka
2009-11-11 12:59 ` Jan Kiszka
2009-11-15 17:38 ` Philippe Gerum
2009-11-16 12:38 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091020113726.9069.91437.stgit@domain.hid \
--to=jan.kiszka@domain.hid \
--cc=rpm@xenomai.org \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.