diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2012-08-06 16:07:38 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-07 08:53:42 +0200 |
commit | 39c2fdd9070f81705f1de927694b8589f69da149 (patch) | |
tree | 9798334ca22aed7a367e1328c7fe735213944b4f /src/gui/kernel/qwindowsysteminterface_p.h | |
parent | 4ec169a60f9270a9ba673857de90e3b38ac94e7c (diff) |
QWindowSystemInterface: fix mem leak and race
There was a race where QGuiApplicationPrivate::processMouseEvent accessed
QWindowSystemInterfacePrivate::windowSystemEventQueue without holding
QWindowSystemInterfacePrivate::queueMutex.
There was a memory leak where QWindowSystemInterfacePrivate::windowSystemEventQueue
would not delete events contained in it when it was destroyed.
Fix both of these by properly encapsulating the QList/QMutex pair
in a small class, WindowSystemEventList, that allows only properly protected access
to the internal QList and calls qDeleteAll() in its dtor.
Change-Id: Ifaa9968c9272096df2f7109a7a6cf1c8e5fa736c
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src/gui/kernel/qwindowsysteminterface_p.h')
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface_p.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 26f4cd68bb..f39e473b29 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -45,6 +45,8 @@ #include <QElapsedTimer> #include <QPointer> +#include <QMutex> +#include <QList> QT_BEGIN_HEADER @@ -323,8 +325,27 @@ public: qint64 uid; }; - static QList<WindowSystemEvent *> windowSystemEventQueue; - static QMutex queueMutex; + class WindowSystemEventList { + QList<WindowSystemEvent *> impl; + mutable QMutex mutex; + public: + WindowSystemEventList() : impl(), mutex() {} + ~WindowSystemEventList() + { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); } + + void prepend(WindowSystemEvent *e) + { const QMutexLocker locker(&mutex); impl.prepend(e); } + WindowSystemEvent *takeFirstOrReturnNull() + { const QMutexLocker locker(&mutex); return impl.empty() ? 0 : impl.takeFirst(); } + void append(WindowSystemEvent *e) + { const QMutexLocker locker(&mutex); impl.append(e); } + int count() const + { const QMutexLocker locker(&mutex); return impl.count(); } + private: + Q_DISABLE_COPY(WindowSystemEventList); + }; + + static WindowSystemEventList windowSystemEventQueue; static int windowSystemEventsQueued(); static WindowSystemEvent * getWindowSystemEvent(); |