summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Achtelik <mike.achtelik@gmail.com>2020-06-09 13:55:15 +0200
committerMike Achtelik <mike.achtelik@gmail.com>2020-06-23 21:59:54 +0200
commit5dc4004afc05f2ccfda3421a61b9f91c5cbcc640 (patch)
tree3a415ce51172f869a148e24e691f28e3b3a7668b
parentf6d1be7c66782e718b23dc0905b60a975b19e14c (diff)
Fix living QLibrary member after shutdown of QCoreApplication
LibResolv uses a QLibrary which is a QObject that must be deleted if the QCoreApplication is being destroyed to release the underlying library. A Q_GLOBAL_STATIC won't release any memory and is not able to manually release it. Pick-to: 5.15 Task-number: QTBUG-84234 Change-Id: I97fe5faca309e9c1e85435f602ad7f8c3f633b48 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/network/kernel/qhostinfo_unix.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp
index 625fbabf31..9b0a2ee669 100644
--- a/src/network/kernel/qhostinfo_unix.cpp
+++ b/src/network/kernel/qhostinfo_unix.cpp
@@ -156,7 +156,25 @@ LibResolv::LibResolv()
}
}
}
-Q_GLOBAL_STATIC(LibResolv, libResolv)
+
+LibResolv* libResolv()
+{
+ static LibResolv* theLibResolv = nullptr;
+ static QBasicMutex theMutex;
+
+ const QMutexLocker locker(&theMutex);
+ if (theLibResolv == nullptr) {
+ theLibResolv = new LibResolv();
+ Q_ASSERT(QCoreApplication::instance());
+ QObject::connect(QCoreApplication::instance(), &QCoreApplication::destroyed, [] {
+ const QMutexLocker locker(&theMutex);
+ delete theLibResolv;
+ theLibResolv = nullptr;
+ });
+ }
+
+ return theLibResolv;
+}
static void resolveLibrary(LibResolvFeature f)
{