fixed a memleak spotted by cppcheck