When using Valgrind, I noticed that it only generates the Heap Summary when the process is terminating. Is there a way to force Valgrind to scan the memory and print leak reports when process is still running?
In addition to the VALGRIND_DO_LEAK_CHECK
client request, you can also run valgrind with --vgdb=yes
to enable embedded gdbserver, and then issue monitor leak_check full reachable any
command at the (gdb)
prompt.
This doesn't require modifying and rebuilding the target program, and has other advantages: you can set breakpoints and perform leak checks at arbitrary points in the execution, not just the ones where you've put in the client request.