cppcheck: fix memory leaks