Fix memory leaks
Merge pull request #1291 from sjinks/memleaks

[1.3.0] Fix memory leaks