[Bug libstdc++/39366] New: Memory Leak in Exception Handling
fgiasson1 at yahoo dot ca
gcc-bugzilla@gcc.gnu.org
Wed Mar 4 19:54:00 GMT 2009
When an exception is thrown for the first time in a given thread, there is a 16
bytes memory leak if the thread is started by a C++ library loaded using
dlopen() by a C executable.
The key factors to reproduce the leak are:
- The executable must be a C program not linked against libstdc++ and not
linked against the faulty C++ library;
- The C++ library must be loaded using dlopen();
- A leak will occur the first time a thread started by the C++ library throws
an exception.
The problem was not present in libstdc++ 6.0.3 (distributed with GCC 3.4.6),
but is present in libstdc++ 6.0.9 and libstdc++ 6.0.10.
Attached is a gzip-compressed tarball containing:
-------------------------------------------------
main.c: The source file for the executable;
dummy.cpp: The source file for the C++ library;
build.sh: The bash shell script used to compile;
main.i, main.ii: The preprocessed outputs.
Command line to compile:
------------------------
cd /cpp_exception_test; ./build.sh testlib.so
Example command line to execute:
--------------------------------
cd /cpp_exception_test; ./cpp_exception_test /cpp_exception_test 10
Note that Valgrind reports an 8 bytes leak per thread throwing a first
exception, but the memory growth seen when running a large number of iterations
is 16 bytes.
Extract from Valgrind report:
-----------------------------
==16376== 8 bytes in 1 blocks are definitely lost in loss record 1 of 12
==16376== at 0x402517F: memalign (vg_replace_malloc.c:460)
==16376== by 0x401055F: ___tls_get_addr (in /lib/ld-2.7.so)
==16376== by 0x46528AA: (anonymous namespace)::get_global()
(eh_globals.cc:55)
==16376== by 0x4652375: __cxa_allocate_exception (eh_alloc.cc:134)
==16376== by 0x459ED41: ExceptionFunction(int) (in
/home/fg/cpp_exception_test/libtest.so)
==16376== by 0x459EDE4: DummyThread(void*) (in
/home/fg/cpp_exception_test/libtest.so)
==16376== by 0x402D4FA: start_thread (in
/lib/tls/i686/cmov/libpthread-2.7.so)
==16376== by 0x4123E5D: clone (in /lib/tls/i686/cmov/libc-2.7.so)
gcc -v output:
--------------
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ./configure --quiet --enable-languages=c,c++
--prefix=/opt/gcc/4.2.4
Thread model: posix
gcc version 4.2.4
uname -a output:
----------------
Linux fred-laptop 2.6.24-19-generic #1 SMP Fri Jul 11 23:41:49 UTC 2008 i686
GNU/Linux
Linux distribution: Ubuntu 8.0.4 (Hardy Heron)
--
Summary: Memory Leak in Exception Handling
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: fgiasson1 at yahoo dot ca
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39366
More information about the Gcc-bugs
mailing list