diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2012-03-02 11:10:23 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-05 16:37:16 +0100 |
commit | b7ba68515023995e998039d92780dded8bbfd325 (patch) | |
tree | d2240a21ae0ebb1e911a114e9e9de89b181e23ab /src | |
parent | e1ec8727ea94153ebdf2b06184de20901f1facb9 (diff) |
Don't leak from QPlatformPrinterSupportPlugin::get()
Cache the first QPlatformPrinterSupport returned from the first
QPlatformPrinterSupportPlugin, and treat it as an persistent singelton.
Change-Id: Ic1c83d7c1cdf4a09723a74e0b9fd485e0b0b3acb
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/printsupport/kernel/qplatformprintplugin.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/src/printsupport/kernel/qplatformprintplugin.cpp b/src/printsupport/kernel/qplatformprintplugin.cpp index 409de3eb4a..2c87fcc5e6 100644 --- a/src/printsupport/kernel/qplatformprintplugin.cpp +++ b/src/printsupport/kernel/qplatformprintplugin.cpp @@ -58,15 +58,27 @@ QPlatformPrinterSupportPlugin::~QPlatformPrinterSupportPlugin() { } +/*! + \internal + + Returns a lazily-initialized singleton. Ownership is granted to the + QPlatformPrinterSupportPlugin, which is never unloaded or destroyed until + application exit, i.e. you can expect this pointer to always be valid and + multiple calls to this function will always return the same pointer. +*/ QPlatformPrinterSupport *QPlatformPrinterSupportPlugin::get() { - QStringList k = loader()->keys(); - if (k.isEmpty()) - return 0; - QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first())); - if (!plugin) - return 0; - return plugin->create(k.first()); + static QPlatformPrinterSupport *singleton = 0; + if (!singleton) { + QStringList k = loader()->keys(); + if (k.isEmpty()) + return 0; + QPlatformPrinterSupportPlugin *plugin = qobject_cast<QPlatformPrinterSupportPlugin *>(loader()->instance(k.first())); + if (!plugin) + return 0; + singleton = plugin->create(k.first()); + } + return singleton; } QT_END_NAMESPACE |