fix error and mem leak found by cppcheck
Merge pull request #5 from greg-a/master

fix error and mem leak found by cppcheck