Fix memory errors detected by valgrind
Merge pull request #3 from crumblingstatue/master

Fix memory errors detected by valgrind