Fix some memory leaks

Please review, I'm unsure about two maybe required memset's.