aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarja Hassinen <marja.hassinen@nokia.com>2010-09-10 15:46:24 +0300
committerMarja Hassinen <marja.hassinen@nokia.com>2010-09-10 15:46:24 +0300
commit3714b71e80ff510478768fcd7b95c6426a6f99b3 (patch)
treea93c1a22877288631da2dbdc9f0ba178321dfb4e
parent35b80f9157c7d5a20f7bf1c80eab988e429f3174 (diff)
Lame attempts to "fix" the qAddPostRoutine problems.
qAddPostRoutine problems: when libcontextsubscriber is unloaded, QCoreApplication will still contain a reference to a function in it, and it will crash.
-rw-r--r--libcontextsubscriber/src/infobackend.cpp19
-rw-r--r--libcontextsubscriber/src/infobackend.h2
2 files changed, 19 insertions, 2 deletions
diff --git a/libcontextsubscriber/src/infobackend.cpp b/libcontextsubscriber/src/infobackend.cpp
index 419cd780..614c90e6 100644
--- a/libcontextsubscriber/src/infobackend.cpp
+++ b/libcontextsubscriber/src/infobackend.cpp
@@ -72,6 +72,15 @@ InfoBackend* InfoBackend::instance(const QString &backendName)
// Move the backend to the main thread
backendInstance->moveToThread(QCoreApplication::instance()->thread());
+ // We must ensure that:
+ // 1) QFileSystemWatcher is deleted before QCoreApplication.
+ // 2) libcontextsubscriber can be unloaded successfully
+ // (QCoreApplication cannot have a post routine that is inside a library
+ // that has been unloaded.)
+
+ // For 1), we add a post routine to QCoreApplication for deleting the
+ // QFileSystemWathcer, for 2) we remove the post routine and delete the
+ // QFileSystemWatcher when the library is unloaded.
qAddPostRoutine(destroyInstance);
}
@@ -149,6 +158,14 @@ void InfoBackend::disconnectNotify(const char *signal)
void InfoBackend::destroyInstance()
{
delete backendInstance;
- backendInstance = NULL;
+ backendInstance = 0;
}
+/// This will be called when the library is unloaded.
+void __attribute__((destructor)) library_dtor()
+{
+ // It seems to be ok to call qRemovePostRoutine even if QCoreApplication
+ // doesn't exist any more.
+ qRemovePostRoutine(InfoBackend::destroyInstance);
+ InfoBackend::destroyInstance();
+}
diff --git a/libcontextsubscriber/src/infobackend.h b/libcontextsubscriber/src/infobackend.h
index cc4d7c90..ff37e1e6 100644
--- a/libcontextsubscriber/src/infobackend.h
+++ b/libcontextsubscriber/src/infobackend.h
@@ -37,6 +37,7 @@ class InfoBackend : public QObject
public:
static InfoBackend* instance(const QString &backendName = "");
+ static void destroyInstance();
/// Returns the name of the backend, ie: 'xml'.
virtual QString name() const = 0;
@@ -95,7 +96,6 @@ private:
InfoBackend& operator=(const InfoBackend&);
static InfoBackend* backendInstance; ///< Holds a pointer to the instance of the singelton.
- static void destroyInstance();
friend class InfoXmlBackend;
friend class InfoCdbBackend;