[cppcheck-fix]Fix memory leaks and parse error

See #286, newest comment.
Merge pull request #518 from tpaviot/review/cppcheck-fixes

Fix cppcheck errors