Abusing valgrind to find reference leaks

Maarten Lankhorst m.b.lankhorst at gmail.com
Tue Apr 29 18:18:40 CDT 2008


Hi all,

I've managed to abuse valgrind to show backtraces of all places where
an AddRef and Release is called when there is a memory, this is
superior to wading through an endless pile of logs without even
guarantee it will work.

I thought I should share it for the following reasons:
1. Valgrind is an awesome tool
2. Reference leaks are usually impossible or very hard to find by
using debug logs

All I'm doing is leaking memory until the destructor is called, which
gives quite useful results, I had to add a exit(1) after the leak
occured because the samples get destroyed regardless when the
interface controlling those samples is released.

The log was created with:
valgrind --trace-children=yes --leak-check=full --show-reachable=yes
--leak-resolution=high -- wine quartz_test.exe.so filtergraph 2>&1 |
tee valgrind.log

And then I removed all the memory leaks and warnings not related to
AddRef and Release.

Ideally I could get it to automatically sort the outputted data based
on the order of calling, but I'm not 100% sure how to do that yet. I
could do 1,000,000 + GetTickCount(), but the results are usable now
regardless.

This was useful for me to get the backtraces of all _AddRef's and
_Release's *ONLY* for the leaking interfaces, which saves a lot of
time determining whether the specific interface is leaking and not,
and when it starts leaking, and then determining who calls and where
it is called, so I hope it is useful for you too!

Cheers,
Maarten.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: valgrind.log
Type: text/x-log
Size: 7041 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20080429/1c23bfbd/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memallocator.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20080429/1c23bfbd/attachment-0001.bin 


More information about the wine-devel mailing list