|
From: Craig V. <cv...@no...> - 2005-03-18 20:10:58
|
Is the following memory leak reported by valgrind a bug in my code or a bug with valgrind? I'm not sure how a user of pthread_create() could cause this? ==751== 200 bytes in 1 blocks are definitely lost in loss record 305 of 332 ==751== at 0x404DEE5B: (within /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==751== by 0x404E09F1: (within /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==751== by 0x404E0B24: __pthread_key_create (in /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==751== by 0x404E133E: (within /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==751== by 0x404DF72C: pthread_create (in /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==751== by 0x40EE0964: tenv::TenvAgInit::TenvAgInit() (agInit.cc:142) ==751== by 0x40EE03D1: __static_initialization_and_destruction_0(int, int) (agGlob.cc:56) ==751== by 0x40EE045A: _GLOBAL__I__ZN4tenv8perProcTE (agGlob.cc:56) ==751== by 0x40EE9FD4: (within /mnt/cmp/lib/libtenvag.so.1.3.0) ==751== by 0x40EDF7FD: (within /mnt/cmp/lib/libtenvag.so.1.3.0) ==751== by 0x4000B5C0: _dl_init_internal (in /lib/ld-2.3.2.so) ==751== by 0x40000A8C: (within /lib/ld-2.3.2.so) This report used to look like the following: ==749== 200 bytes in 1 blocks are definitely lost in loss record 306 of 333 ==749== at 0x404DEE5B: (within /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==749== by 0x404E09F1: (within /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==749== by 0x404E0B24: __pthread_key_create (in /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==749== by 0x406E2842: (within /lib/libc-2.3.2.so) ==749== by 0x404E0E47: __pthread_once (in /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) ==749== by 0x406E2808: inet_ntoa (in /lib/libc-2.3.2.so) ==749== by 0x40EE9473: tenv::getOwnIp(unsigned&, unsigned char&, unsigned char&) (utils.cc:984) ==749== by 0x40EE0831: tenv::TenvAgInit::TenvAgInit() (agInit.cc:90) ==749== by 0x40EE03D1: __static_initialization_and_destruction_0(int, int) (agGlob.cc:56) ==749== by 0x40EE045A: _GLOBAL__I__ZN4tenv8perProcTE (agGlob.cc:56) ==749== by 0x40EE9F54: (within /mnt/image/opt/msp/lib/libtenvag.so.1.3.0) ==749== by 0x40EDF7FD: (within /mnt/image/opt/msp/lib/libtenvag.so.1.3.0) ==749== by 0x4000B5C0: _dl_init_internal (in /lib/ld-2.3.2.so) ==749== by 0x40000A8C: (within /lib/ld-2.3.2.so) But I replaced the use of "inet_ntoa" with "inet_ntop" and that changed the traceback. [root]# valgrind --version valgrind-2.0.0 Valgrind options used: --leak-check=yes --leak-resolution=high --num-callers=15 myProg What is happening? Two threads are created as part of a C++ global constructor via a call to pthread_create(). The leak is reported when the process is being terminated. There is a corresponding descructor which cancels the threads ( via pthread_cancel() )and does a pthread_join() on each before exiting. Cheers, Craig |
|
From: Nicholas N. <nj...@cs...> - 2005-03-18 20:18:12
|
On Fri, 18 Mar 2005, Craig Verge wrote: > Is the following memory leak reported by valgrind a bug in my code or a bug > with valgrind? I'm not sure how a user of pthread_create() could cause > this? > > ==751== 200 bytes in 1 blocks are definitely lost in loss record 305 of 332 > ==751== at 0x404DEE5B: (within > /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) > ==751== by 0x404E09F1: (within > /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) > ==751== by 0x404E0B24: __pthread_key_create (in > /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) > ==751== by 0x404E133E: (within > /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) > ==751== by 0x404DF72C: pthread_create (in > /mnt/image/opt/msp/tools/lib/valgrind/libpthread.so) > ==751== by 0x40EE0964: tenv::TenvAgInit::TenvAgInit() (agInit.cc:142) > ==751== by 0x40EE03D1: __static_initialization_and_destruction_0(int, > int) (agGlob.cc:56) > ==751== by 0x40EE045A: _GLOBAL__I__ZN4tenv8perProcTE (agGlob.cc:56) > ==751== by 0x40EE9FD4: (within /mnt/cmp/lib/libtenvag.so.1.3.0) > ==751== by 0x40EDF7FD: (within /mnt/cmp/lib/libtenvag.so.1.3.0) > ==751== by 0x4000B5C0: _dl_init_internal (in /lib/ld-2.3.2.so) > ==751== by 0x40000A8C: (within /lib/ld-2.3.2.so) I'm guessing it's a Valgrind bug. We had a 200-byte leak in our libpthread.so. It's normally suppressed but it seems that on your system valgrind's libpthread.so has been stripped, so the suppression won't match. If you try 2.4.0-rc4 (www.goop.org/~jeremy/valgrind/dist/), we now use the system libpthread, and the leak checker has been improved, so hopefully the problem will no longer be present. N |