|
Boost : |
From: Jeremie Detrey (Jeremie.Detrey_at_[hidden])
Date: 2005-05-11 09:58:52
Hello,
It seems to me that there is a possibly huge memory leak in the file
boost/libs/thread/src/tss.cpp, as the thread specific data slot vector
is allocated (line 120) but never freed.
It causes a few bytes' memory leak for each thread, as it appears when
using valgrind (see attached files: input program = example.cpp,
valgrind output = example.valgrind).
I propose here a simple patch to fix this. It works perfectly with my
programs, and frankly I cannot see why it should not work.
Thanks,
Jeremie Detrey.
==32551== Memcheck, a memory error detector for x86-linux.
==32551== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==32551== Using valgrind-2.4.0, a program supervision framework for x86-linux.
==32551== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==32551== For more details, rerun with: -v
==32551==
==32551==
==32551== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 25 from 1)
==32551== malloc/free: in use at exit: 1092 bytes in 13 blocks.
==32551== malloc/free: 23 allocs, 10 frees, 1152 bytes allocated.
==32551== For counts of detected errors, rerun with: -v
==32551== searching for pointers to 13 not-freed blocks.
==32551== checked 42165256 bytes.
==32551==
==32551== 60 bytes in 5 blocks are definitely lost in loss record 3 of 5
==32551== at 0x1B906727: operator new(unsigned) (vg_replace_malloc.c:132)
==32551== by 0x1B937C51: (anonymous namespace)::get_slots(bool) (in /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x1B937EBB: boost::detail::tss::set(void*) (in /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x8049534: boost::thread_specific_ptr<int>::reset(int*) (in ./example)
==32551== by 0x8049344: thread_proc() (in ./example)
==32551== by 0x8049A4C: boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::any_pointer) (in ./example)
==32551== by 0x1B9378EF: boost::function0<void, std::allocator<boost::function_base> >::operator()() const (in /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x1B93751C: (within /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x1BA2CB62: start_thread (in /lib/tls/libpthread-0.60.so)
==32551== by 0x1BB12189: clone (in /lib/tls/libc-2.3.2.so)
==32551==
==32551==
==32551== 340 bytes in 5 blocks are possibly lost in loss record 4 of 5
==32551== at 0x1B906F75: calloc (vg_replace_malloc.c:175)
==32551== by 0x1B8F2588: (within /lib/ld-2.3.2.so)
==32551== by 0x1B8F285B: _dl_allocate_tls (in /lib/ld-2.3.2.so)
==32551== by 0x1BA2D24A: allocate_stack (in /lib/tls/libpthread-0.60.so)
==32551== by 0x1BA2CC54: pthread_create@@GLIBC_2.1 (in /lib/tls/libpthread-0.60.so)
==32551== by 0x1B936AC1: boost::thread::thread(boost::function0<void, std::allocator<boost::function_base> > const&) (in /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x1B937179: boost::thread_group::create_thread(boost::function0<void, std::allocator<boost::function_base> > const&) (in /usr/lib/libboost_thread-gcc-mt-1_32.so.1.32.0)
==32551== by 0x8049425: main (in ./example)
==32551==
==32551== LEAK SUMMARY:
==32551== definitely lost: 60 bytes in 5 blocks.
==32551== possibly lost: 340 bytes in 5 blocks.
==32551== still reachable: 692 bytes in 3 blocks.
==32551== suppressed: 0 bytes in 0 blocks.
==32551== Reachable blocks (those to which a pointer was found) are not shown.
==32551== To see them, rerun with: --show-reachable=yes
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk