Re: [Xenomai-help] Xenomai-forge: tm_evafter without tm_cancel causes memory leaks.

2011-09-27 Thread Philippe Gerum
On Mon, 2011-09-26 at 23:28 +0200, Ronny Meeus wrote:
 Hello
 
 As for as I know it is not mandatory call tm_cancel on a one-shot
 timer to cleanup the resources in the OS.
 This means that if the timer expires, the event is sent and all
 resources are released by pSOS at that time.
 
 Since I did not see a test for this in the testsuite, I created one
 myself (in fact 2, see attachments).
 This time it is a small piece of code :-).
 In this test I create a task that starts 100 events timers
 (tm_evafter) but does not stop them (no tm_cancel is called).
 
 In the first test (tm-10.c) I create a task that starts 100 timers,
 sleeps some time and deletes itself.
 This sleeping allows the timers to expire. This is the result if I run 
 valgrind:
 

[snip]

 So it looks like the contexts allocated in start_evtimer are at least
 lost, but valgrind mentions another 100 blocks that are still
 reachable but I think these are in fact also lost since these are
 referenced by the timer contexs.
 

[snip]

Ack, it would not make sense to leave elapsed oneshot timers alive. The
code is now fixed.


 
 I also have created a similar test application (tm-11), but in this
 code the sleep is not there. This means the timers are still running
 while killing the task. When running this test, I see an invalid read:
 

Confirmed. Albeit the deletion code was there, it was badly broken. At
this chance, the invalid timer error code returned by all timer
routines has been fixed as well.

I merged a slightly adapted version of these tests as tm-6 and tm-7 in
the psos testsuite. Thanks.

-- 
Philippe.



___
Xenomai-help mailing list
Xenomai-help@gna.org
https://mail.gna.org/listinfo/xenomai-help


Re: [Xenomai-help] Xenomai-forge: tm_evafter without tm_cancel causes memory leaks.

2011-09-27 Thread Ronny Meeus
On Tue, Sep 27, 2011 at 10:09 AM, Philippe Gerum r...@xenomai.org wrote:
 On Mon, 2011-09-26 at 23:28 +0200, Ronny Meeus wrote:
 Hello

 As for as I know it is not mandatory call tm_cancel on a one-shot
 timer to cleanup the resources in the OS.
 This means that if the timer expires, the event is sent and all
 resources are released by pSOS at that time.

 Since I did not see a test for this in the testsuite, I created one
 myself (in fact 2, see attachments).
 This time it is a small piece of code :-).
 In this test I create a task that starts 100 events timers
 (tm_evafter) but does not stop them (no tm_cancel is called).

 In the first test (tm-10.c) I create a task that starts 100 timers,
 sleeps some time and deletes itself.
 This sleeping allows the timers to expire. This is the result if I run 
 valgrind:


 [snip]

 So it looks like the contexts allocated in start_evtimer are at least
 lost, but valgrind mentions another 100 blocks that are still
 reachable but I think these are in fact also lost since these are
 referenced by the timer contexs.


 [snip]

 Ack, it would not make sense to leave elapsed oneshot timers alive. The
 code is now fixed.



 I also have created a similar test application (tm-11), but in this
 code the sleep is not there. This means the timers are still running
 while killing the task. When running this test, I see an invalid read:


 Confirmed. Albeit the deletion code was there, it was badly broken. At
 this chance, the invalid timer error code returned by all timer
 routines has been fixed as well.

 I merged a slightly adapted version of these tests as tm-6 and tm-7 in
 the psos testsuite. Thanks.

 --
 Philippe.




I tried the latest version of the repo and the problem is resolved.
Thanks for the quick response.

Ronny

___
Xenomai-help mailing list
Xenomai-help@gna.org
https://mail.gna.org/listinfo/xenomai-help


[Xenomai-help] Xenomai-forge: tm_evafter without tm_cancel causes memory leaks.

2011-09-26 Thread Ronny Meeus
Hello

As for as I know it is not mandatory call tm_cancel on a one-shot
timer to cleanup the resources in the OS.
This means that if the timer expires, the event is sent and all
resources are released by pSOS at that time.

Since I did not see a test for this in the testsuite, I created one
myself (in fact 2, see attachments).
This time it is a small piece of code :-).
In this test I create a task that starts 100 events timers
(tm_evafter) but does not stop them (no tm_cancel is called).

In the first test (tm-10.c) I create a task that starts 100 timers,
sleeps some time and deletes itself.
This sleeping allows the timers to expire. This is the result if I run valgrind:

meeusr@meeusr-laptop:~/repo/xenomai-forge/lib/psos/testsuite$ sudo
LD_LIBRARY_PATH=/home/meeusr/repo/xenomai-forge-install/lib/ valgrind
--leak-check=full ./tm-10
==2399== Memcheck, a memory error detector
==2399== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==2399== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==2399== Command: ./tm-10
==2399==
^C==2399==
==2399== HEAP SUMMARY:
==2399== in use at exit: 11,090 bytes in 203 blocks
==2399==   total heap usage: 311 allocs, 108 frees, 13,646 bytes allocated
==2399==
==2399== 136 bytes in 1 blocks are possibly lost in loss record 2 of 5
==2399==at 0x402425F: calloc (vg_replace_malloc.c:467)
==2399==by 0x4010CDB: _dl_allocate_tls (dl-tls.c:300)
==2399==by 0x405C2E2: pthread_create@@GLIBC_2.1 (allocatestack.c:561)
==2399==by 0x402F9F1: t_create (task.c:307)
==2399==by 0x80486F0: main (tm-10.c:27)
==2399==
==2399== 136 bytes in 1 blocks are possibly lost in loss record 3 of 5
==2399==at 0x402425F: calloc (vg_replace_malloc.c:467)
==2399==by 0x4010CDB: _dl_allocate_tls (dl-tls.c:300)
==2399==by 0x405C2E2: pthread_create@@GLIBC_2.1 (allocatestack.c:561)
==2399==by 0x4074201: __start_helper_thread (timer_routines.c:184)
==2399==by 0x406142F: pthread_once (pthread_once.S:122)
==2399==by 0x403EBFA: timerobj_init (timerobj-mercury.c:69)
==2399==by 0x403056F: start_evtimer (tm.c:101)
==2399==by 0x4030623: tm_evafter (tm.c:126)
==2399==by 0x804865D: task (tm-10.c:13)
==2399==by 0x402F559: task_trampoline (task.c:193)
==2399==by 0x405B96D: start_thread (pthread_create.c:300)
==2399==by 0x4145A4D: clone (clone.S:130)
==2399==
==2399== 5,200 bytes in 100 blocks are possibly lost in loss record 4 of 5
==2399==at 0x4024F20: malloc (vg_replace_malloc.c:236)
==2399==by 0x403FFB8: pvmalloc (heapobj-malloc.c:75)
==2399==by 0x40304B8: start_evtimer (tm.c:81)
==2399==by 0x4030623: tm_evafter (tm.c:126)
==2399==by 0x804865D: task (tm-10.c:13)
==2399==by 0x402F559: task_trampoline (task.c:193)
==2399==by 0x405B96D: start_thread (pthread_create.c:300)
==2399==by 0x4145A4D: clone (clone.S:130)
==2399==
==2399== LEAK SUMMARY:
==2399==definitely lost: 0 bytes in 0 blocks
==2399==indirectly lost: 0 bytes in 0 blocks
==2399==  possibly lost: 5,472 bytes in 102 blocks
==2399==still reachable: 5,618 bytes in 101 blocks
==2399== suppressed: 0 bytes in 0 blocks
==2399== Reachable blocks (those to which a pointer was found) are not shown.
==2399== To see them, rerun with: --leak-check=full --show-reachable=yes
==2399==
==2399== For counts of detected and suppressed errors, rerun with: -v
==2399== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 21 from 8)
Killed

So it looks like the contexts allocated in start_evtimer are at least
lost, but valgrind mentions another 100 blocks that are still
reachable but I think these are in fact also lost since these are
referenced by the timer contexs.


I also have created a similar test application (tm-11), but in this
code the sleep is not there. This means the timers are still running
while killing the task. When running this test, I see an invalid read:

meeusr@meeusr-laptop:~/repo/xenomai-forge/lib/psos/testsuite$ sudo
LD_LIBRARY_PATH=/home/meeusr/repo/xenomai-forge-install/lib/ valgrind
--leak-check=full ./tm-11
==2521== Memcheck, a memory error detector
==2521== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==2521== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
copyright info
==2521== Command: ./tm-11
==2521==
==2521== Thread 2:
==2521== Invalid read of size 4
==2521==at 0x402F0A1: threadobj_get_magic (threadobj.h:226)
==2521==by 0x402F1C7: find_psos_task (task.c:55)
==2521==by 0x402F279: get_psos_task (task.c:94)
==2521==by 0x403021C: ev_send (task.c:631)
==2521==by 0x4030494: postman_handler (tm.c:71)
==2521==by 0x403EB13: timerobj_handler (timerobj-mercury.c:39)
==2521==by 0x4074432: timer_sigev_thread (timer_routines.c:65)
==2521==by 0x405B96D: start_thread (pthread_create.c:300)
==2521==by 0x4145A4D: clone (clone.S:130)
==2521==  Address 0x41d4190 is 136 bytes inside a block of size 584 free'd
==2521==at 0x4024B3A: free