fix some memory allocation issues
fix memleak
Merge pull request #4 from tmatth/alloc_fixes

Fix some memory allocation issues