|
From: Roberto D. <rd...@ti...> - 2007-12-27 09:16:30
|
Hello everybody.
I need help to understand the followind valgrind traces:
Invalid free() / delete / delete[]
==19141== at 0x4004EFA: free (vg_replace_malloc.c:235)
==19141== by 0x4058947: borra_hb_sc (moncv.cpp:142)
==19141== by 0x42124D1: Comunicaciones::Hilo::Mutex::~Mutex()
(Hilo.cpp:254)
==19141== by 0x425C757: __tcf_7 (ServicioLog.cpp:40)
==19141== by 0xB5C7A3: __cxa_finalize (in /lib/tls/libc-2.3.4.so)
==19141== by 0x41E2CBD: (within
/home/manager/roberto/pruebas_enza/libNuevosComunicadores.so)
==19141== by 0x426F56D: (within
/home/manager/roberto/pruebas_enza/libNuevosComunicadores.so)
==19141== by 0xB20906: _dl_fini (in /lib/ld-2.3.4.so)
==19141== by 0xB5C526: exit (in /lib/tls/libc-2.3.4.so)
^^^^
==19141== by 0xB46DEC: (below main) (in /lib/tls/libc-2.3.4.so)
==19141== Address 0x43E3FA8 is 0 bytes inside a block of size 40 free'd
==19141== at 0x4004EFA: free (vg_replace_malloc.c:235)
==19141== by 0x4058947: borra_hb_sc (moncv.cpp:142)
==19141== by 0x42124D1: Comunicaciones::Hilo::Mutex::~Mutex()
(Hilo.cpp:254)
==19141== by 0x80616D9: __tcf_7 (ServicioLog.cpp:40)
==19141== by 0xB5C526: exit (in /lib/tls/libc-2.3.4.so)
^^^^
==19141== by 0xB46DEC: (below main) (in /lib/tls/libc-2.3.4.so)
It seems free is being called from exit.. which is calling _tcf_7 and
then is also calling _dl_fini which also calls _tcf_7 and causes a
double free.
The double free is happening in some static class variables I have into
libNuevosComunicadores.so.. I do not understand how is that my
destructors are being called twice.
Any help will be quite appreciated.
Best Regards
Roberto
|
|
From: Dan K. <da...@ke...> - 2007-12-27 11:57:03
|
On Dec 27, 2007 1:16 AM, Roberto Diaz <rd...@ti...> wrote: > It seems free is being called from exit.. which is calling _tcf_7 and > then is also calling _dl_fini which also calls _tcf_7 and causes a > double free. > > The double free is happening in some static class variables I have into > libNuevosComunicadores.so.. I do not understand how is that my > destructors are being called twice. This is one example of how static objects can cause trouble. I advise avoiding them entirely. They can be used safely when absolutely necessary, but it sometimes requires more platform knowledge than the casual developer usually cares to acquire. This is because the C++ standard didn't really define static object construction and destruction rigorously. The Linux C++ ABI tries to fix that, see http://www.codesourcery.com/cxx-abi/abi.html#dso-dtor This was probably not fully implemented until gcc-3.3 or so. So, what compiler are you using? - Dan |
|
From: Dan K. <da...@ke...> - 2007-12-27 16:27:35
|
On Dec 27, 2007 3:57 AM, Dan Kegel <da...@ke...> wrote: > On Dec 27, 2007 1:16 AM, Roberto Diaz <rd...@ti...> wrote: > > The double free is happening in some static class variables I have into > > libNuevosComunicadores.so.. I do not understand how is that my > > destructors are being called twice. After all my lecture, Roberto reported that the problem was caused by him including a source file in twice! - Dan |