probably memory leak: abi::__cxa_demangle()
template <typename Base>
bool PluginManager::IsLibraryLoaded(const std::string& class_name) {
int status = 0;
std::string base_class_name =
abi::__cxa_demangle(typeid(Base).name(), 0, 0, &status);
if (plugin_class_plugin_name_map_.find({class_name, base_class_name}) ==
plugin_class_plugin_name_map_.end()) {
// not found
return false;
}
std::string plugin_name =
plugin_class_plugin_name_map_[{class_name, base_class_name}];
if (plugin_loaded_map_.find(plugin_name) == plugin_loaded_map_.end()) {
// not found
return false;
}
return plugin_loaded_map_[plugin_name];
}
as shown, a string obj constructed with a ptr returned by __cxa_demangle(), but never free. and the string obj may not able to free this memory, who always destruct its own memory. I'm curious if there is a memory leak here.
many thanks for your reply.
there's a memory leak.
Returns: A pointer to the start of the NUL-terminated demangled name, or NULL if the demangling fails. The caller is responsible for deallocating this memory using free.
abi::__cxa_demangle malloc the memory, and caller need to free it. So there's a memory leak
there's a memory leak.
Returns: A pointer to the start of the NUL-terminated demangled name, or NULL if the demangling fails. The caller is responsible for deallocating this memory using free.
abi::__cxa_demanglemalloc the memory, and caller need to free it. So there's a memory leak
OK. Not only this function, there are other functions call abi::__cxa_demangle and lost the memory. Like in file modules/planning/planning_interface_base/task.cc,Task::Init(), is where the worst impact is, will cause a persistent memory leak.