This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: libstdc++/9147: Memory leak resulting from std::valarray->push_back(arg)



On 2 Jan 2003 bkoz@gcc.gnu.org wrote:

> Synopsis: Memory leak resulting from std::valarray->push_back(arg)
> 
> Responsible-Changed-From-To: unassigned->bkoz
> Responsible-Changed-By: bkoz
> Responsible-Changed-When: Thu Jan  2 15:01:58 2003
> Responsible-Changed-Why:
>     Mine.
> State-Changed-From-To: open->feedback
> State-Changed-By: bkoz
> State-Changed-When: Thu Jan  2 15:01:58 2003
> State-Changed-Why:
>     You seem a bit confused. First, there is no push_back method for valarray. Second, this simple program:

You are quite correct, I meant vector!  Darn!

>     
>     #include <valarray>
>     
>     int main()
>     {
>       std::valarray<double> a(20);
>       a.resize(40);
>       return 0;
>     }
>     
>     Shows no valgrind leaks. 
>     
>     More on that part: you'll need to use valgrind 1.0.4 or later with gcc-3.2 toolchains (as indicated by the valgrind RELEASE NOTES: I suggest a careful reading.) 

Ok, good to know...

>     
>     After that, I suggest this page, which has gcc/libstdc++ specific hints on how to use valgrind:
>     http://gcc.gnu.org/onlinedocs/libstdc++/debug.html

I haven't seen this one yet, will check it out...

>     
>     Sadly, 3.2.0 shipped with some memory leaks that have since been fixed in the 3.2.1 release: I suggest you use the later version of gcc if possible.

Excellent.  


>     
>     Here is the valgrind output for 3.2.1, running on linux. The leaks shown (8bytes) are known issues:

Ok, I will read this carefully, and watch the gcc pages as well.

Thanks for your time, this has been very helpful
and I will do better next time I file an bug.

Dave Doolin



>     
>     %valgrind.sh a.out
>     ==3718== valgrind-1.0.4, a memory error detector for x86 GNU/Linux.
>     ==3718== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
>     ==3718== Startup, with flags:
>     ==3718==    --suppressions=/mnt/hd/bld/H-x86-valgrind/lib/valgrind/default.supp
>     ==3718==    -v
>     ==3718==    --num-callers=20
>     ==3718==    --leak-check=yes
>     ==3718==    --leak-resolution=high
>     ==3718==    --show-reachable=yes
>     ==3718== Reading suppressions file: /mnt/hd/bld/H-x86-valgrind/lib/valgrind/default.supp
>     ==3718== Reading syms from /home/bkoz/a.out
>     ==3718== Reading syms from /lib/ld-2.3.1.so
>     ==3718==    object doesn't have any debug info
>     ==3718== Reading syms from /mnt/hd/bld/H-x86-valgrind/lib/valgrind/valgrind.so
>     ==3718== Reading syms from /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libstdc++.so.5.0.1
>     ==3718== Reading syms from /lib/i686/libm-2.3.1.so
>     ==3718==    object doesn't have any debug info
>     ==3718== Reading syms from /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libgcc_s.so.1
>     ==3718== Reading syms from /lib/i686/libc-2.3.1.so
>     ==3718==    object doesn't have any debug info
>     ==3718== Estimated CPU clock rate is 751 MHz
>     ==3718==
>     ==3718==
>     ==3718== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
>     ==3718== malloc/free: in use at exit: 8 bytes in 4 blocks.
>     ==3718== malloc/free: 6 allocs, 2 frees, 488 bytes allocated.
>     ==3718==
>     ==3718== searching for pointers to 4 not-freed blocks.
>     ==3718== checked 4459624 bytes.
>     ==3718==
>     ==3718== definitely lost: 0 bytes in 0 blocks.
>     ==3718== possibly lost:   0 bytes in 0 blocks.
>     ==3718== still reachable: 8 bytes in 4 blocks.
>     ==3718==
>     ==3718== 2 bytes in 1 blocks are still reachable in loss record 1 of 4
>     ==3718==    at 0x4003C9D1: __builtin_vec_new (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:156)
>     ==3718==    by 0x4003CA1A: operator new[](unsigned) (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:170)
>     ==3718==    by 0x402A3589: std::locale::_Impl::_Impl(std::locale::facet**, unsigned, bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:1643)
>     ==3718==    by 0x4028513A: std::locale::classic() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/libsupc++/new:89)
>     ==3718==    by 0x402839C5: std::locale::locale() (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/localefwd.h:298)
>     ==3718==    by 0x402747C7: ??? (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/streambuf:356)
>     ==3718==    by 0x40273512: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/ext/stdio_filebuf.h:146)
>     ==3718==    by 0x4027CC67: std::ios_base::Init::_S_ios_create(bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/basic_ios.h:186)
>     ==3718==    by 0x4027D235: std::ios_base::Init::Init() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/src/ios.cc:211)
>     ==3718==    by 0x4027C9B8: __static_initialization_and_destruction_0(int, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/iostream:63)
>     ==3718==    by 0x4027CA2A: _GLOBAL__I__ZThn8_NSt14basic_iostreamIwSt11char_traitsIwEED0Ev_mnt_hd_src_gcc_3.2.1_libstdc___v3_src_io_inst.ccWrimhb (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:107)==3718==    by 0x402C8B35: (within /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libstdc++.so.5.0.1)
>     ==3718==    by 0x4026D14E: ??? (/tmp/ccv5AQuj.s:25)
>     ==3718==    by 0x4000A66E: call_init (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x4000A4DA: _dl_init_internal (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x40000AAD: (within /lib/ld-2.3.1.so)
>     ==3718==
>     ==3718== 2 bytes in 1 blocks are still reachable in loss record 2 of 4
>     ==3718==    at 0x4003C9D1: __builtin_vec_new (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:156)
>     ==3718==    by 0x4003CA1A: operator new[](unsigned) (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:170)
>     ==3718==    by 0x402A3490: std::locale::_Impl::_Impl(std::locale::facet**, unsigned, bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:1017)
>     ==3718==    by 0x4028513A: std::locale::classic() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/libsupc++/new:89)
>     ==3718==    by 0x402839C5: std::locale::locale() (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/localefwd.h:298)
>     ==3718==    by 0x402747C7: ??? (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/streambuf:356)
>     ==3718==    by 0x40273512: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/ext/stdio_filebuf.h:146)
>     ==3718==    by 0x4027CC67: std::ios_base::Init::_S_ios_create(bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/basic_ios.h:186)
>     ==3718==    by 0x4027D235: std::ios_base::Init::Init() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/src/ios.cc:211)
>     ==3718==    by 0x4027C9B8: __static_initialization_and_destruction_0(int, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/iostream:63)
>     ==3718==    by 0x4027CA2A: _GLOBAL__I__ZThn8_NSt14basic_iostreamIwSt11char_traitsIwEED0Ev_mnt_hd_src_gcc_3.2.1_libstdc___v3_src_io_inst.ccWrimhb (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:107)==3718==    by 0x402C8B35: (within /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libstdc++.so.5.0.1)
>     ==3718==    by 0x4026D14E: ??? (/tmp/ccv5AQuj.s:25)
>     ==3718==    by 0x4000A66E: call_init (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x4000A4DA: _dl_init_internal (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x40000AAD: (within /lib/ld-2.3.1.so)
>     ==3718==
>     ==3718== 2 bytes in 1 blocks are still reachable in loss record 3 of 4
>     ==3718==    at 0x4003C9D1: __builtin_vec_new (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:156)
>     ==3718==    by 0x4003CA1A: operator new[](unsigned) (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:170)
>     ==3718==    by 0x402A312F: std::locale::_Impl::_Impl(std::locale::facet**, unsigned, bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:1643)
>     ==3718==    by 0x4028513A: std::locale::classic() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/libsupc++/new:89)
>     ==3718==    by 0x402839C5: std::locale::locale() (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/localefwd.h:298)
>     ==3718==    by 0x402747C7: ??? (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/streambuf:356)
>     ==3718==    by 0x40273512: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/ext/stdio_filebuf.h:146)
>     ==3718==    by 0x4027CC67: std::ios_base::Init::_S_ios_create(bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/basic_ios.h:186)
>     ==3718==    by 0x4027D235: std::ios_base::Init::Init() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/src/ios.cc:211)
>     ==3718==    by 0x4027C9B8: __static_initialization_and_destruction_0(int, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/iostream:63)
>     ==3718==    by 0x4027CA2A: _GLOBAL__I__ZThn8_NSt14basic_iostreamIwSt11char_traitsIwEED0Ev_mnt_hd_src_gcc_3.2.1_libstdc___v3_src_io_inst.ccWrimhb (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:107)==3718==    by 0x402C8B35: (within /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libstdc++.so.5.0.1)
>     ==3718==    by 0x4026D14E: ??? (/tmp/ccv5AQuj.s:25)
>     ==3718==    by 0x4000A66E: call_init (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x4000A4DA: _dl_init_internal (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x40000AAD: (within /lib/ld-2.3.1.so)
>     ==3718==
>     ==3718== 2 bytes in 1 blocks are still reachable in loss record 4 of 4
>     ==3718==    at 0x4003C9D1: __builtin_vec_new (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:156)
>     ==3718==    by 0x4003CA1A: operator new[](unsigned) (/mnt/hd/src/valgrind-1.0.4/vg_clientfuncs.c:170)
>     ==3718==    by 0x402A3032: std::locale::_Impl::_Impl(std::locale::facet**, unsigned, bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:1017)
>     ==3718==    by 0x4028513A: std::locale::classic() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/libsupc++/new:89)
>     ==3718==    by 0x402839C5: std::locale::locale() (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/localefwd.h:298)
>     ==3718==    by 0x402747C7: ??? (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/streambuf:356)
>     ==3718==    by 0x40273512: __gnu_cxx::stdio_filebuf<char, std::char_traits<char> >::stdio_filebuf(_IO_FILE*, std::_Ios_Openmode, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/ext/stdio_filebuf.h:146)
>     ==3718==    by 0x4027CC67: std::ios_base::Init::_S_ios_create(bool) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/basic_ios.h:186)
>     ==3718==    by 0x4027D235: std::ios_base::Init::Init() (/mnt/hd/src/gcc-3.2.1/libstdc++-v3/src/ios.cc:211)
>     ==3718==    by 0x4027C9B8: __static_initialization_and_destruction_0(int, int) (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/iostream:63)
>     ==3718==    by 0x4027CA2A: _GLOBAL__I__ZThn8_NSt14basic_iostreamIwSt11char_traitsIwEED0Ev_mnt_hd_src_gcc_3.2.1_libstdc___v3_src_io_inst.ccWrimhb (/mnt/hd/bld/bld-x86-gcc-3.2.1/i686-pc-linux-gnu/libstdc++-v3/include/bits/locale_facets.h:107)==3718==    by 0x402C8B35: (within /mnt/hd/bld/H-x86-gcc-3.2.1/lib/libstdc++.so.5.0.1)
>     ==3718==    by 0x4026D14E: ??? (/tmp/ccv5AQuj.s:25)
>     ==3718==    by 0x4000A66E: call_init (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x4000A4DA: _dl_init_internal (in /lib/ld-2.3.1.so)
>     ==3718==    by 0x40000AAD: (within /lib/ld-2.3.1.so)
>     ==3718==
>     ==3718== LEAK SUMMARY:
>     ==3718==    definitely lost: 0 bytes in 0 blocks.
>     ==3718==    possibly lost:   0 bytes in 0 blocks.
>     ==3718==    still reachable: 8 bytes in 4 blocks.
>     ==3718==
>     --3718--       lru: 0 epochs, 0 clearings.
>     --3718-- translate: new 1485 (22684 -> 269355), discard 0 (0 -> 0).
>     --3718--  dispatch: 0 basic blocks, 2/1516 sched events, 1505 tt_fast misses.
>     --3718-- reg-alloc: 424 t-req-spill, 49567+2984 orig+spill uis, 7245 total-reg-r.
>     --3718--    sanity: 3 cheap, 1 expensive checks.
>     
>     
>     
> 
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9147
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]