Fix memory leaks reported by cppcheck
Merge pull request #318 from serval2412/master

Fix memory leaks reported by cppcheck