All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Posix Memory Leak w/ sem_open
@ 2011-06-28 18:25 Henry Bausley
  2011-06-28 18:59 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Henry Bausley @ 2011-06-28 18:25 UTC (permalink / raw)
  To: xenomai


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.

root@domain.hid# uname -a
Linux powerpmac 2.6.35.9 #4 Tue Jun 28 08:45:19 PDT 2011 ppc GNU/Linux
root@domain.hid# cat /proc/xenomai/version 
2.5.6
root@domain.hid#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9600:pagesz=512  (main heap)
root@domain.hid#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9632:pagesz=512  (main heap)
root@domain.hid#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9664:pagesz=512  (main heap)
root@domain.hid#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9696:pagesz=512  (main heap)
root@domain.hid#  test/test && cat /proc/xenomai/heap | grep
main
size=520192:used=9728:pagesz=512  (main heap)
root@domain.hid#  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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Posix Memory Leak w/ sem_open
  2011-06-28 18:25 [Xenomai-help] Posix Memory Leak w/ sem_open Henry Bausley
@ 2011-06-28 18:59 ` Gilles Chanteperdrix
  2011-06-29 14:53   ` Henry Bausley
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2011-06-28 18:59 UTC (permalink / raw)
  To: Henry Bausley; +Cc: xenomai

On 06/28/2011 08:25 PM, Henry Bausley wrote:
> 
> 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.
> 
Should be fixed with the following patch:

diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
index 3c7f7ee..c9e84a6 100644
--- a/ksrc/skins/posix/syscall.c
+++ b/ksrc/skins/posix/syscall.c
@@ -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));
 }


> 
> 
> 
> 
> 
> 
> 
> Outbound scan for Spam or Virus by Barracuda at Delta Tau
> 
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help
> 


-- 
                                                                Gilles.


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Xenomai-help] Posix Memory Leak w/ sem_open
  2011-06-28 18:59 ` Gilles Chanteperdrix
@ 2011-06-29 14:53   ` Henry Bausley
  0 siblings, 0 replies; 3+ messages in thread
From: Henry Bausley @ 2011-06-29 14:53 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai

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

On Tue, 2011-06-28 at 20:59 +0200, Gilles Chanteperdrix wrote:
> On 06/28/2011 08:25 PM, Henry Bausley wrote:
> > 
> > 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.
> > 
> Should be fixed with the following patch:
> 
> diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c
> index 3c7f7ee..c9e84a6 100644
> --- a/ksrc/skins/posix/syscall.c
> +++ b/ksrc/skins/posix/syscall.c
> @@ -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));
>  }
> 
> 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > Outbound scan for Spam or Virus by Barracuda at Delta Tau
> > 
> > 
> > _______________________________________________
> > Xenomai-help mailing list
> > Xenomai-help@domain.hid
> > https://mail.gna.org/listinfo/xenomai-help
> > 
> 
> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-29 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-28 18:25 [Xenomai-help] Posix Memory Leak w/ sem_open Henry Bausley
2011-06-28 18:59 ` Gilles Chanteperdrix
2011-06-29 14:53   ` Henry Bausley

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.