I'm trying to fix a memory leak in a very large project. Benchmarks have confirmed that memory leaks are a significant problem, and I'm working on finding the source of them.
Running the project on a very simple case, I get ~850 potential memory leaks reported. All but about 5 of them look like:
==83597== 768 bytes in 3 blocks are possibly lost in loss record 743 of 864
==83597== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==83597== by 0x548EF93: myproject_malloc (mysourcefile.c:48)
==83597== by 0x4F13FD5: ??? (in /path/to/project/library-version.so)
==83597== by 0x1101: ???
==83597== by 0xF7: ???
==83597== by 0x64D4D87: ???
==83597== by 0xFFFFFFFFFFFFFFFD: ???
==83597== by 0x6: ???
==83597== by 0x4F03BB0: ??? (in /path/to/project/library-version.so)
==83597== by 0xFFFFFFFFFFFFFFFD: ???
==83597== by 0x64D4D87: ???
==83597== 920 bytes in 1 blocks are possibly lost in loss record 750 of 864
==83597== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==83597== by 0x548EF93: myproject_malloc (mysourcefile.c:48)
==83597== by 0x4F13FD5: ??? (in /path/to/project/library-version.so)
==83597== by 0xFFEFFFD5F: ???
==83597== by 0x38F: ???
==83597== by 0xFFEFFFE5F: ???
==83597== by 0xF: ???
==83597== by 0x54542FF: ??? (in /path/to/project/library-version.so)
==83597== by 0x4F536CA: ??? (in /path/to/project/library-version.so)
==83597== by 0x64B981F: ???
==83597== by 0xF: ???
==83597== by 0x54542FF: ??? (in /path/to/project/library-version.so)
==83597== 1,360 bytes in 1 blocks are possibly lost in loss record 789 of 864
==83597== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==83597== by 0x548EF93: myproject_malloc (mysourcefile.c:48)
==83597== by 0x4F13FD5: ??? (in /path/to/project/library-version.so)
==83597== by 0x1101: ???
==83597== by 0x547: ???
==83597== by 0x1F: ???
==83597== by 0x6584267: ???
==83597== by 0x547: ???
==83597== by 0x4F13808: ??? (in /path/to/project/library-version.so)
==83597== by 0x6584267: ???
==83597== by 0x6584527: ???
==83597== by 0x65805FF: ???
I'm working on getting valgrind to give real, useful output rather than ???, but it may not be possible, and I'd like to be able to get useful output from memcheck until that happens.
A useful report has > 1 function call reported from a real source file rather than a .so file (because every output reports myproject_malloc as a potential leak source). What's the simplest way I can cut out all of the junk from the output and still display it as plain text in my emacs compilation buffer?
I know I could write a Python script that would be a few dozen lines long to do the job by checking every time I enter a new error report and counting the number of times I see ".c:\d+", but I'd prefer something simpler.
Is there a nice way to do this with commandline tools? Or an option to valgrind that I'm not aware of?