Fix memory leaks

Fixes for some of the memory leaks reported by Apple's Instruments