Memory leak detection code added

added some code to find some of the more obvious memory leaks in the
code, there are still however others left in the code somewhere.