Catching memory leaks in XS

 I slay dragons, yonder

So I am trying to find and plug memory leaks in SDL perl. Most of the memory leaks occur because in XS a reference is still held. One very expensive mem leak was caught by TELS really early on here. The problem occurs where in XS there is

RETVAL = (cast *) safemalloc( ... );
 and safefree(...) is never called.
Here is a in code example lines 1082 on.

My question is how I can mitigate these memory leaks? One idea I had was to store all malloc'd pointers to an array that is safefree'd on DESTROY or hooked into perl GC somehow .


Any guidance is helpful.

--yapgh