Fixed memory leaks reported by cppcheck.

Fixed memory leaks reported by cppcheck static analysis tool.