Fixed memory leaks reported by cppcheck.