QPluginLoader Memory leaks?
-
Hi all,
My application is using QPluginLoader, and valgrind is reporting memory leaks with QPluginLoader.
@==5181== 604 (96 direct, 508 indirect) bytes in 1 blocks are definitely lost in loss record 167 of 216
==5181== at 0x4A08361: operator new(unsigned long) (vg_replace_malloc.c:298)
==5181== by 0x5C4DE11: ??? (in /opt/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5.0.2)
==5181== by 0x5C42FD8: QPluginLoader::setFileName(QString const&) (in /opt/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5.0.2)
==5181== by 0x5C448B0: QPluginLoader::QPluginLoader(QString const&, QObject*) (in /opt/Qt5.0.2/5.0.2/gcc_64/lib/libQt5Core.so.5.0.2)
==5181== by 0x40911E: main_window_t::load_tools() (mainwindow.cpp:390)
==5181== by 0x40963A: main_window_t::main_window_t() (mainwindow.cpp:42)
==5181== by 0x4065BC: main (in /home/branden/Repositories/DR-GUI/bin/DR-GUI)@My code is
@foreach (QString file_name, plugins_dir.entryList(QDir::Files)) {
QPluginLoader loader(plugins_dir.absoluteFilePath(file_name), this);
QObject *plugin = loader.instance();
if (plugin != NULL) {
tool_interface_t *i_tool;
i_tool = qobject_cast<tool_interface_t *>(plugin);
if (i_tool) {
add_to_menu(plugin, i_tool->tool_names(),
tool_menu, SLOT(add_tab()), tool_action_group);
plugins.append(i_tool);
}
plugin_file_names += file_name;
} else {
QMessageBox::about(this, tr("About DR-GUI"),
loader.errorString());
}
}@There are also memory leaks on QPluginLoader::instance.
I am storing the _i_tool_s in the QVector plugins and deleting them in the destructor of main_window_t. plugin and i_tool point to the same memory loc, so I don't need to store & delete both, deleting it twice would be bad.
The full source can be found on "github":https://github.com/clarkb7/DR-GUI
Though I've updated it a little since I pushed it yesterday, it should still have these leaks.Any ideas? Thanks