Fix leaks after profiling

Fix some memory leaks found after profiling.