This is the mail archive of the mailing list for the libstdc++ 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]

Memory Leak using STL - gcc-3.2 and gcc-2.95.3

Dear Sirs,
	After checking for leaks in C++ programs compiled with gcc I found the
following, both in 3.2and 2.95.3

Some memory was always leaked when using the STL, found using mtrace()
in glibc.

C++ code:

main.cpp is:
#include <list>
#include <mcheck.h>
using namespace std;
void boo() {
   list<int> l;
int main()
  return 0;
saj@sajX RotaryDB $ export MALLOC_TRACE="log"
saj@sajX RotaryDB $ /opt/gcc-3/bin/g++ --version
saj@sajX RotaryDB $ /opt/gcc-3/bin/g++ -g -o test main.cpp  saj@sajX
saj@sajX RotaryDB $ ./test
saj@sajX RotaryDB $ mtrace test log

Memory not freed:
   Address     Size     Caller
0x0804a028    0x280  at

saj@sajX RotaryDB $ cat log
= Start
@ /opt/gcc-3/lib/[0x4007a80e] + 0x804a028

did a backtrace using gdb of the offending malloc:

(gdb) bt
#0  operator new(unsigned) (sz=640) at
#1  0x4009ef21 in std::__default_alloc_template<true,
0>::_S_chunk_alloc(unsigned, int&) (__size=16, __nobjs=@0xbffff4d8)
#2  0x4009ee3d in std::__default_alloc_template<true,
0>::_S_refill(unsigned) (__n=16) at
#3  0x4009ea10 in std::__default_alloc_template<true,
0>::allocate(unsigned) (__n=640) at
#4  0x08048bac in std::__simple_alloc<std::_List_node<int>,
std::__default_alloc_template<true, 0> >::allocate(unsigned) (__n=1) at
#5  0x08048b02 in std::_List_alloc_base<int, std::allocator<int>,
true>::_M_get_node() (this=0x804a0c8) at
#6  0x08048aa1 in _List_base (this=0x804a0c8, __a=@0xbffff5b4) at
#7  0x08048a64 in list (this=0x804a0c8, __a=@0xbffff5b4) at
#8  0x08048976 in main () at main2.cpp:7
#9  0x40125401 in __libc_start_main () from /lib/

Many thanks,
	Stefan Jones (plz CC me in replys)

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