Fix memory leaks
Merge pull request #382 from HughPowell/master

Fix memory leaks