use-after-free in engine finalize callback
I bet I'm doing something wrong, but valgrind is complaining about a invalid write in thallium.
I'm following REMI's model of doing cleanup in a margo finalize callback:
It looks like when thallium is setting the
m_finalized_called flag ( e->m_finalize_called = true; ) the engine has already been deallocated.
How should I re-order the memory cleanup to make this work?
==11746== Invalid write of size 1 ==11746== at 0x5053960: store (atomic_base.h:374) ==11746== by 0x5053960: operator= (atomic_base.h:267) ==11746== by 0x5053960: operator= (atomic:79) ==11746== by 0x5053960: thallium::engine::on_finalize_cb(void*) (engine.hpp:150) ==11746== by 0x56868D9: margo_cleanup (margo.c:556) ==11746== by 0x10958E: main (server.c:113) ==11746== Address 0xbb2b7a2 is 66 bytes inside a block of size 136 free'd ==11746== at 0x4C3123B: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==11746== by 0x504F773: bv_on_finalize(void*) (bv-provider.cc:685) ==11746== by 0x56868D9: margo_cleanup (margo.c:556) ==11746== by 0x10958E: main (server.c:113) ==11746== Block was alloc'd at ==11746== at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==11746== by 0x504F8D7: bv_svc_provider_register (bv-provider.cc:698) ==11746== by 0x109576: main (server.c:109)