[cppcheck-fix]Fix memory leaks and parse error

See #286, newest comment.