Note that there are some explanatory texts on larger screens.

plurals
  1. PODebugging a crash that does not happen inside a debugger
    text
    copied!<p>I split a monolithic piece of code into dynamically loaded library and <code>main()</code> that calls it. I use no other library than stdc++, nor are there any classes, just a templated struct that has no member functions. I am not allocating any memory explicitly nor deleting or freeing anything in the code. I do use erase objects from a <code>list&lt;T&gt;</code>.</p> <p>After the switch to library + main I am getting intermittent crashes.</p> <p><code>*** glibc detected *** : free(): invalid pointer:</code></p> <p>From the backtrace it seems a list itertor is involved, but the name mangled symbols make it hard to be sure.</p> <p>However it does not crash inside gdb, nor does valgrind detect any memory corruption or leaks.</p> <p>I have not build shared libraries before. This is what I am using</p> <p><code>g++ -fPIC -shared library_src.cpp -o libblaH.so</code></p> <p><code>g++ main.cpp -lblaH</code></p> <p>The entirety of the library is in a single source file, the library function is wrapped in an <code>extern "C"</code> block to make it accessible to c users, but right now i am compiling main() with g++ as a c++ code.</p> <p>Now when I add optimization options, <code>-O2</code> (in particular) I start getting the crashes.</p> <p>I have tried <code>electricfence</code> it says the invalid pointer was not allocated by malloc.</p> <p>I would appreciate suggestions on how to hunt the bug down. My feeling is that I am invalidation a list iterator somewhere, but how I am not sure. I thought they cant be invalidated, except for deleted entries.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload