Fix memory leaks
Merge pull request #7 from DanWin/master

Fix memory leaks