Module: xenomai-2.5
Branch: master
Commit: b8a3cb67d64879db42a286b421a9a74cc75fdb95
URL:    
http://git.xenomai.org/?p=xenomai-2.5.git;a=commit;h=b8a3cb67d64879db42a286b421a9a74cc75fdb95

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Jun 28 21:08:06 2011 +0200

posix: fix leak in user-space named semaphores

---

 ksrc/skins/posix/syscall.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 39f78ab..c9e443d 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -700,17 +700,20 @@ static int __sem_close(struct pt_regs *regs)
 
        usm = assoc2usem(assoc);
 
-       if ((closed = (--usm->refcnt == 0)))
+       err = sem_close(&sm.native_sem);
+
+       if (!err && (closed = (--usm->refcnt == 0)))
                pse51_assoc_remove(&pse51_queues()->usems,
                                   (u_long)sm.shadow_sem.sem);
 
-       err = sem_close(&sm.native_sem);
-
        xnlock_put_irqrestore(&pse51_assoc_lock, s);
 
        if (err)
                return -thread_get_errno();
 
+       if (usm->refcnt == 0)
+               xnfree(usm);
+
        return __xn_safe_copy_to_user((void __user *)__xn_reg_arg2(regs),
                                      &closed, sizeof(int));
 }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to