Fix memory leak detected by Cppcheck