Valery Pykhtin wrote:
> Hi all,
>> It seems there is a memory leak when deleting a task used printf.
>> I created the test:
>> 1. Calculating the amount of free/used blocks in c heap using
> _Heap_Get_information.
> 2. Starting new task
> 3. Task does printf and selfdeletes
> 4. Calculating the amount of free/used blocks in c heap using
> _Heap_Get_information.
> 5. Comparing values before starting a task with values after.
> 6. Goto point 1
If newlib is allocating the memory implicitly, then the
thread-exit delete extension in cpukit/libcsupport/src/newlibc.c
should be doing or calling something that frees it. Look at
that code and see if it is missing something.
This wouldn't be the first time that newlib allocated memory
that it's clean up routines did not account for.
> After each iteration the number of used blocks is continously
> increasing. To catch the bandit I created memory allocation tracer wich
> logs every _Heap_Allocate and _Heap_Free and (log include stack traces
> for each allocation) and marks those blocks that were not freed.
>> The stack trace of the bandit:
>> #0 __wrap__Heap_Allocate
> #1 _Region_Allocate_segment
> #2 rtems_region_get_segment
> #3 malloc
> #4 _malloc_r
> #5 __smakebuf at newlib/libc/stdio/makebuf.c:81
> #6 __swsetup at newlib/libc/stdio/wsetup.c:63
> #7 _vfprintf_r at newlib/libc/stdio/vfprintf.c:519
> #8 vfprintf at newlib/libc/stdio/vfprintf.c:367
> #9 printf at newlib/libc/stdio/printf.c:62
> #10 TestTask
>> where TestTask is my test task, __wrap__Heap_Allocate - _Heap_Allocate
> wrapper.
>> I can send the test I've used, it contains the memory allocation tracer
> and completly ready to run under debugger. My BSP is pc586. Note that
> the test uses builtin GCC functions __builtin_frame_address and
> __builtin_return_address.
>> Tommorow I'm going to repeat the test with RTEMS 4.6.2
>> Valery
>
--
Joel Sherrill, Ph.D. Director of Research & Development
joel at OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985