Memory leak fix

Fix 3 memory leaks pointed out by valgrind.

@kintel , @donbright any objections against merging that into master? Or should this wait for unstable?