Fix some memory leaks
Merge pull request #1581 from nulltoken/fix/leaks

Fix some memory leaks