Fixing some memory leak spotted by CppCheck.