------- Comment #3 from mirko dot maischberger at gmail dot com 2006-06-07 17:43 ------- Subject: Re: valgrind reports memleak when std::ios:sync_with_stdio(false)
#include <iostream> #include <cstdlib> extern "C" void __libc_freeres(void); int main(void) { atexit(__libc_freeres); std::ios::sync_with_stdio(false); std::cout << "ten bytes" << std::endl; return 0; } [EMAIL PROTECTED]:~$ g++-4.1 sync_with_stdio.cc [EMAIL PROTECTED]:~$ valgrind -v --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes ./a.out ==20104== Memcheck, a memory error detector. ==20104== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al. ==20104== Using LibVEX rev 1575, a library for dynamic binary translation. ==20104== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP. ==20104== Using valgrind-3.1.1-Debian, a dynamic binary instrumentation framework. ==20104== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al. ==20104== --20104-- Command line --20104-- ./a.out --20104-- Startup, with flags: --20104-- --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp --20104-- -v --20104-- --num-callers=20 --20104-- --leak-check=yes --20104-- --leak-resolution=high --20104-- --show-reachable=yes --20104-- Contents of /proc/version: --20104-- Linux version 2.6.15-1-k7 (Debian 2.6.15-8) ([EMAIL PROTECTED]) (gcc version 4.0.3 20060212 (prerelease) (Debian 4.0.2-9)) #2 Mon Mar 6 15:42:39 UTC 2006 --20104-- Arch and subarch: X86, x86-sse1 --20104-- Valgrind library directory: /usr/lib/valgrind --20104-- Reading syms from /lib/ld-2.3.6.so (0x4000000) --20104-- Reading debug info from /lib/ld-2.3.6.so... --20104-- ... CRC mismatch (computed A0828FFB wanted BF5D33FD) --20104-- Reading debug info from /usr/lib/debug/lib/ld-2.3.6.so... --20104-- object doesn't have a symbol table --20104-- Reading syms from /home/tesi/a.out (0x8048000) --20104-- Reading syms from /usr/lib/valgrind/x86-linux/memcheck (0xA000000) --20104-- object doesn't have a dynamic symbol table --20104-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp --20104-- Reading suppressions file: /usr/lib/valgrind/default.supp --20104-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_core.so (0x4018000) --20104-- Reading syms from /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so (0x401A000) --20104-- Reading syms from /usr/lib/libstdc++.so.6.0.8 (0x403C000) --20104-- object doesn't have a symbol table --20104-- Reading syms from /usr/lib/debug/libm-2.3.6.so (0x411E000) --20104-- Reading syms from /lib/libgcc_s.so.1 (0x4144000) --20104-- object doesn't have a symbol table --20104-- Reading syms from /usr/lib/debug/libc-2.3.6.so (0x414F000) --20104-- REDIR: 0x41BAAB0 (rindex) redirected to 0x401CE90 (rindex) --20104-- REDIR: 0x41BB6D0 (memset) redirected to 0x401D440 (memset) --20104-- REDIR: 0x41BA680 (strlen) redirected to 0x401D0B0 (strlen) --20104-- REDIR: 0x40EF6B0 (operator new[](unsigned)) redirected to 0x401BC40 (operator new[](unsigned)) --20104-- REDIR: 0x41BBBF0 (memcpy) redirected to 0x401D540 (memcpy) ten bytes --20104-- REDIR: 0x41B4900 (free) redirected to 0x401BFC6 (free) ==20104== ==20104== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 1) --20104-- --20104-- supp: 17 Debian libc6 stripped dynamic linker ==20104== malloc/free: in use at exit: 122,880 bytes in 6 blocks. ==20104== malloc/free: 6 allocs, 0 frees, 122,880 bytes allocated. ==20104== ==20104== searching for pointers to 6 not-freed blocks. ==20104== checked 96,388 bytes. ==20104== ==20104== 8,192 bytes in 1 blocks are still reachable in loss record 1 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D7B: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x4098805: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x408632E: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== ==20104== 8,192 bytes in 1 blocks are still reachable in loss record 2 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D7B: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x4098805: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x4086302: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== ==20104== 8,192 bytes in 1 blocks are still reachable in loss record 3 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D7B: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x4098805: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40862D6: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== ==20104== 32,768 bytes in 1 blocks are still reachable in loss record 4 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D2E: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40981F5: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x408640C: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== ==20104== 32,768 bytes in 1 blocks are still reachable in loss record 5 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D2E: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40981F5: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40863E0: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== ==20104== 32,768 bytes in 1 blocks are still reachable in loss record 6 of 6 ==20104== at 0x401BCC9: operator new[](unsigned) (vg_replace_malloc.c:197) ==20104== by 0x4090D2E: std::basic_filebuf<wchar_t, std::char_traits<wchar_t> >::_M_allocate_internal_buffer() (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40981F5: (within /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x40863B4: std::ios_base::sync_with_stdio(bool) (in /usr/lib/libstdc++.so.6.0.8) ==20104== by 0x804877E: main (in /home/tesi/a.out) ==20104== ==20104== LEAK SUMMARY: ==20104== definitely lost: 0 bytes in 0 blocks. ==20104== possibly lost: 0 bytes in 0 blocks. ==20104== still reachable: 122,880 bytes in 6 blocks. ==20104== suppressed: 0 bytes in 0 blocks. --20104-- memcheck: sanity checks: 6 cheap, 1 expensive --20104-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use --20104-- memcheck: auxmaps: 0 searches, 0 comparisons --20104-- memcheck: secondaries: 11 issued (704k, 0M) --20104-- memcheck: secondaries: 33 accessible and distinguished (2112k, 2M) --20104-- tt/tc: 5,236 tt lookups requiring 5,329 probes --20104-- tt/tc: 5,236 fast-cache updates, 2 flushes --20104-- translate: new 2,614 (57,683 -> 908,750; ratio 157:10) [0 scs] --20104-- translate: dumped 0 (0 -> ??) --20104-- translate: discarded 0 (0 -> ??) --20104-- scheduler: 320,402 jumps (bb entries). --20104-- scheduler: 6/2,728 major/minor sched events. --20104-- sanity: 7 cheap, 1 expensive checks. --20104-- exectx: 30,011 lists, 12 contexts (avg 0 per list) --20104-- exectx: 23 searches, 11 full compares (478 per 1000) --20104-- exectx: 0 cmp2, 38 cmp4, 15 cmpAll -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27931