Fix memory leaks & Use correct "delete" for arrays
Merge pull request #2208 from asmaloney/mem_problems

Fix memory leaks & use correct "delete" for arrays