Merge pull request #317 from serval2412/master

Fix some cppcheck warnings
Fix memory leaks reported by cppcheck