I am trying to debug a use after free error in my code using Valgrind.
My code is crashing when it tries to access an object that was previously deleted. Is there some way to see who deleted the object in this case using Valgrind?
I ran Valgrind using the following option, but it only catches the crash, and shows where it occurred. I’m hoping to get details on where the object was deallocated:
valgrind –tool=memcheck
This is what I use in these cases:
In case of a use-after-free, it will show you the stacktrace of the function that free’d the memory/deleted the object.
Please read the manpage of Valgrind for the caveats, specifically the ones about performance. If your issue is a concurrency problem, a slower Valgrind might change the timing properties of your program and possibly change (either reduce or increase) the probability to hit the bug.