https://bugs.kde.org/show_bug.cgi?id=421931
Bug ID: 421931 Summary: Enhance valgrind to supress unfreed stderr. Product: valgrind Version: 3.15 SVN Platform: Fedora RPMs OS: Linux Status: REPORTED Severity: wishlist Priority: NOR Component: general Assignee: jsew...@acm.org Reporter: car...@redhat.com Target Milestone: --- SUMMARY In glibc the __libc_freeres() function which handles freeing all resources for allocation trackers, will not free unbuffered streams. We don't free unbuffered streams because users may expect to continue using them throughout all of the process shutdown steps. As such, when you use stderr in your program it creates a leak that can be seen by users. STEPS TO REPRODUCE 1. Create leak.c #include <stdio.h> #include <wchar.h> int main ( void ) { fwprintf ( stderr , L"valgrind error\n" ) ; return 0 ; } 2. Compile. 3. Run with valgrind --leak-check=full --show-leak-kinds=all OBSERVED RESULT valgrind --leak-check=full --show-leak-kinds=all ./leak ==258071== Memcheck, a memory error detector ==258071== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==258071== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==258071== Command: ./leak ==258071== valgrind error ==258071== ==258071== HEAP SUMMARY: ==258071== in use at exit: 5,120 bytes in 2 blocks ==258071== total heap usage: 2 allocs, 0 frees, 5,120 bytes allocated ==258071== ==258071== 1,024 bytes in 1 blocks are still reachable in loss record 1 of 2 ==258071== at 0x483A809: malloc (vg_replace_malloc.c:309) ==258071== by 0x4907FC3: _IO_file_doallocate (filedoalloc.c:101) ==258071== by 0x490940C: _IO_wfile_doallocate (wfiledoalloc.c:70) ==258071== by 0x4916D1F: _IO_doallocbuf (genops.c:347) ==258071== by 0x4916D1F: _IO_doallocbuf (genops.c:342) ==258071== by 0x490FBBF: _IO_wfile_overflow (wfileops.c:429) ==258071== by 0x490D22E: __woverflow (wgenops.c:217) ==258071== by 0x490D22E: _IO_wdefault_xsputn (wgenops.c:317) ==258071== by 0x490D22E: _IO_wdefault_xsputn (wgenops.c:284) ==258071== by 0x490FDF0: _IO_wfile_xsputn (wfileops.c:1011) ==258071== by 0x490FDF0: _IO_wfile_xsputn (wfileops.c:957) ==258071== by 0x4906BC1: buffered_vfprintf (vfprintf-internal.c:2388) ==258071== by 0x4903E4B: __vfwprintf_internal (vfprintf-internal.c:1346) ==258071== by 0x490C439: fwprintf (fwprintf.c:33) ==258071== by 0x401152: main (leak.c:9) ==258071== ==258071== 4,096 bytes in 1 blocks are still reachable in loss record 2 of 2 ==258071== at 0x483A809: malloc (vg_replace_malloc.c:309) ==258071== by 0x49093DC: _IO_wfile_doallocate (wfiledoalloc.c:79) ==258071== by 0x4916D1F: _IO_doallocbuf (genops.c:347) ==258071== by 0x4916D1F: _IO_doallocbuf (genops.c:342) ==258071== by 0x490FBBF: _IO_wfile_overflow (wfileops.c:429) ==258071== by 0x490D22E: __woverflow (wgenops.c:217) ==258071== by 0x490D22E: _IO_wdefault_xsputn (wgenops.c:317) ==258071== by 0x490D22E: _IO_wdefault_xsputn (wgenops.c:284) ==258071== by 0x490FDF0: _IO_wfile_xsputn (wfileops.c:1011) ==258071== by 0x490FDF0: _IO_wfile_xsputn (wfileops.c:957) ==258071== by 0x4906BC1: buffered_vfprintf (vfprintf-internal.c:2388) ==258071== by 0x4903E4B: __vfwprintf_internal (vfprintf-internal.c:1346) ==258071== by 0x490C439: fwprintf (fwprintf.c:33) ==258071== by 0x401152: main (leak.c:9) ==258071== ==258071== LEAK SUMMARY: ==258071== definitely lost: 0 bytes in 0 blocks ==258071== indirectly lost: 0 bytes in 0 blocks ==258071== possibly lost: 0 bytes in 0 blocks ==258071== still reachable: 5,120 bytes in 2 blocks ==258071== suppressed: 0 bytes in 0 blocks ==258071== ==258071== For lists of detected and suppressed errors, rerun with: -s ==258071== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) EXPECTED RESULT - Given that stderr might be used a lot by developers we could enhance valgrind to try supress unfreed unbuffered stderr at process exit. - For a high QoI we would supress all unfreed unbuffered streams since the expectation, at least in glibc, is that none of these are freed with __libc_freeres() because the could continue to be used during process shutdown. SOFTWARE/OS VERSIONS Fedora 32: valgrind-3.15.0-20.fc32.x86_64 ADDITIONAL INFORMATION N/A -- You are receiving this mail because: You are watching all bug changes.