Can you run it under valgrind? (http://valgrind.org/) with the leakcheck option and debug symbols compiled into the executable? This should identify where blocks are being lost.