Hi Fritjof,

frit...@alokat.org wrote on Fri, Dec 25, 2015 at 11:56:33AM +0100:

> it looks like there is a memory leak in libc.
> In file "src/lib/libc/stdio/makebuf.c" line 62 malloc(3) is called,
> but never freed, when printf(3) is called.

I think that's a false positive.  The pointer to the buffer is
stored in the FILE object, specifically in fp->_bf._base,
and that is freed in fclose(3), line 54.

Or do you mean to say that _base is overwritten somewhere while
it still points to the allocated memory?  If so, where specifically?

Yours,
  Ingo


> $ valgrind --leak-check=full --show-leak-kinds=all /usr/sbin/apm
> ==29572== Memcheck, a memory error detector
> ==29572== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==29572== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
> ==29572== Command: /usr/sbin/apm
> ==29572== 
> ==29572== 
> ==29572== FILE DESCRIPTORS: 4 open at exit.
> ==29572== Open file descriptor 3: /dev/apm
> ==29572==    at 0x5443A2A: open (<stdin>:2)
> ==29572==    by 0x1099B6: ??? (in /usr/sbin/apm)
> ==29572==    by 0x108FF0: ??? (in /usr/sbin/apm)
> ==29572== 
> ==29572== Open file descriptor 2:
> ==29572==    <inherited from parent>
> ==29572== 
> ==29572== Open file descriptor 1:
> ==29572==    <inherited from parent>
> ==29572== 
> ==29572== Open file descriptor 0:
> ==29572==    <inherited from parent>
> ==29572== 
> ==29572== 
> ==29572== HEAP SUMMARY:
> ==29572==     in use at exit: 65,536 bytes in 1 blocks
> ==29572==   total heap usage: 1 allocs, 0 frees, 65,536 bytes allocated
> ==29572== 
> ==29572== 65,536 bytes in 1 blocks are still reachable in loss record 1 of 1
> ==29572==    at 0x5019224: malloc (in 
> /usr/local/lib/valgrind/vgpreload_memcheck-amd64-openbsd.so)
> ==29572==    by 0x54AB15B: __smakebuf (makebuf.c:62)
> ==29572==    by 0x54A53A9: __swsetup (wsetup.c:73)
> ==29572==    by 0x548F2F7: __vfprintf (vfprintf.c:462)
> ==29572==    by 0x549211D: vfprintf (vfprintf.c:267)
> ==29572==    by 0x547700B: printf (printf.c:44)
> ==29572==    by 0x109B8F: ??? (in /usr/sbin/apm)
> ==29572==    by 0x108FF0: ??? (in /usr/sbin/apm)
> ==29572== 
> ==29572== LEAK SUMMARY:
> ==29572==    definitely lost: 0 bytes in 0 blocks
> ==29572==    indirectly lost: 0 bytes in 0 blocks
> ==29572==      possibly lost: 0 bytes in 0 blocks
> ==29572==    still reachable: 65,536 bytes in 1 blocks
> ==29572==         suppressed: 0 bytes in 0 blocks
> ==29572== 
> ==29572== For counts of detected and suppressed errors, rerun with: -v
> ==29572== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Reply via email to