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

Fix some memory leaks