Fix memory leaks
Merge pull request #4 from kou/fix-memory-leaks

Fix memory leaks