Skip to contentSkip to conversation

Posix Memory Leak w/ sem_open

Xenomai-help Henry Bausley 2 participants 3 messages Jun 28, 2011 – Jun 29, 2011

lore
Share & tools
lore
#0 lore raw

Using the program below the used main heap continues to grow forever.

int main(void)
{
sem_t *mutex;
mutex = sem_open(SEM_NAME,O_CREAT,0644,1);
sem_close(mutex);
sem_unlink(SEM_NAME);
return 0;
}

I am using xenomai 2.5.6 with the ipipe-2.6.35.9-powerpc-2.12-02 kernel. Below you can see the used heap continually grow when executing the above program.

[email protected]# uname -a
Linux powerpmac 2.6.35.9 #4 Tue Jun 28 08:45:19 PDT 2011 ppc GNU/Linux
[email protected]# cat /proc/xenomai/version 
2.5.6
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9600:pagesz=512  (main heap)
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9632:pagesz=512  (main heap)
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9664:pagesz=512  (main heap)
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9696:pagesz=512  (main heap)
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9728:pagesz=512  (main heap)
[email protected]#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9760:pagesz=512  (main heap)

Outbound scan for Spam or Virus by Barracuda at Delta Tau

#1 lore raw
Quoted 12 lines · Henry Bausley

Using the program below the used main heap continues to grow forever.

int main(void)
{
sem_t *mutex;
mutex = sem_open(SEM_NAME,O_CREAT,0644,1);
sem_close(mutex);
sem_unlink(SEM_NAME);
return 0;
}

Quoted 4 lines

I am using xenomai 2.5.6 with the ipipe-2.6.35.9-powerpc-2.12-02 kernel. Below you can see the used heap continually grow when executing the above program.

Should be fixed with the following patch:

ksrc/skins/posix/syscall.c +6 -3
index 3c7f7ee..c9e84a6 100644
@@ -718,17 +718,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));
 }
Quoted 15 lines

Outbound scan for Spam or Virus by Barracuda at Delta Tau

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Signature · 1 line
                                                                Gilles.
#2 lore raw

Yes the patch solved the problem. Thanks for the rapid response.

Quoted 66 lines · Gilles Chanteperdrix
Quoted 12 lines · Henry Bausley

Using the program below the used main heap continues to grow forever.

int main(void)
{
sem_t *mutex;
mutex = sem_open(SEM_NAME,O_CREAT,0644,1);
sem_close(mutex);
sem_unlink(SEM_NAME);
return 0;
}

Quoted 4 lines

I am using xenomai 2.5.6 with the ipipe-2.6.35.9-powerpc-2.12-02 kernel. Below you can see the used heap continually grow when executing the above program.

Should be fixed with the following patch:

ksrc/skins/posix/syscall.c +6 -3
index 3c7f7ee..c9e84a6 100644
@@ -718,17 +718,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));
 }
Quoted 17 lines

Outbound scan for Spam or Virus by Barracuda at Delta Tau

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help