summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-05-06 15:47:28 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-05-08 11:51:13 (GMT)
commit4c7004122a858cd6d891efc7923ba11484fbf997 (patch)
tree5960b1fbd48ac45f9cdf4344692e39c89e21eb9d
parent330bebda90472f12dcbfde5a04600f4f6e97326d (diff)
downloadQt-4c7004122a858cd6d891efc7923ba11484fbf997.zip
Qt-4c7004122a858cd6d891efc7923ba11484fbf997.tar.gz
Qt-4c7004122a858cd6d891efc7923ba11484fbf997.tar.bz2
Fixed leak of plugin instances
It seems that plugins were never explicitly unloaded, resulting in leaks of the instance object. Added a static deleter to ensure deletion on exit. The QPointer (previously in place) ensures we don't do a double-free nor try to access an invalid pointer. Task-number: 253013 Reviewed-by: mariusSO
-rw-r--r--src/corelib/plugin/qplugin.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/corelib/plugin/qplugin.h b/src/corelib/plugin/qplugin.h
index 4d0e53c..121a875 100644
--- a/src/corelib/plugin/qplugin.h
+++ b/src/corelib/plugin/qplugin.h
@@ -63,6 +63,21 @@ typedef QObject *(*QtPluginInstanceFunction)();
void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunction function);
+struct qt_plugin_instance_deleter
+{
+ qt_plugin_instance_deleter(QPointer<QObject> &instance)
+ : instance_(instance)
+ {
+ }
+
+ ~qt_plugin_instance_deleter()
+ {
+ delete instance_;
+ }
+
+ QPointer<QObject> &instance_;
+};
+
#define Q_IMPORT_PLUGIN(PLUGIN) \
extern QT_PREPEND_NAMESPACE(QObject) *qt_plugin_instance_##PLUGIN(); \
class Static##PLUGIN##PluginInstance{ \
@@ -76,8 +91,10 @@ void Q_CORE_EXPORT qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunctio
#define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \
{ \
static QT_PREPEND_NAMESPACE(QPointer)<QT_PREPEND_NAMESPACE(QObject)> _instance; \
- if (!_instance) \
+ if (!_instance) { \
+ static QT_PREPEND_NAMESPACE(qt_plugin_instance_deleter) deleter(_instance); \
_instance = new IMPLEMENTATION; \
+ } \
return _instance; \
}