Fix leaks

@indexzero can you still reproduce leaks with this branch? These are all the leaks `leaks` tool reported.