Fixes for memory leaks

Several memory leaks fixed.