summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@qt.io>2017-10-27 10:53:51 +0200
committerFrederik Gladhorn <frederik.gladhorn@qt.io>2018-05-04 10:56:35 +0000
commit1e9da7b3fd06dd3edd642d0f6479199b5174c928 (patch)
tree27e45a0ad41bd97a4bc68916afffbc9aa6d4a89e
parent10b3286313c78fa380b5fe676a7c14f3ae84f017 (diff)
Accessibility: Fix leaking cached interfaces
When the application closes, we should clear the cache to not run into memory sanitizers claiming that we leak. Change-Id: Ibf9fcda107be6b7f3ed414d7651080aa1f61a3a5 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--src/gui/accessible/qaccessiblecache.cpp6
-rw-r--r--src/gui/accessible/qaccessiblecache_p.h1
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp4
3 files changed, 11 insertions, 0 deletions
diff --git a/src/gui/accessible/qaccessiblecache.cpp b/src/gui/accessible/qaccessiblecache.cpp
index f4242036ce..f11883c370 100644
--- a/src/gui/accessible/qaccessiblecache.cpp
+++ b/src/gui/accessible/qaccessiblecache.cpp
@@ -57,6 +57,12 @@ static void cleanupAccessibleCache()
accessibleCache = nullptr;
}
+QAccessibleCache::~QAccessibleCache()
+{
+ for (QAccessibleInterface *iface: idToInterface.values())
+ delete iface;
+}
+
QAccessibleCache *QAccessibleCache::instance()
{
if (!accessibleCache) {
diff --git a/src/gui/accessible/qaccessiblecache_p.h b/src/gui/accessible/qaccessiblecache_p.h
index f054ee9678..a976277c1d 100644
--- a/src/gui/accessible/qaccessiblecache_p.h
+++ b/src/gui/accessible/qaccessiblecache_p.h
@@ -68,6 +68,7 @@ class Q_GUI_EXPORT QAccessibleCache :public QObject
Q_OBJECT
public:
+ ~QAccessibleCache() override;
static QAccessibleCache *instance();
QAccessibleInterface *interfaceForId(QAccessible::Id id) const;
QAccessible::Id idForInterface(QAccessibleInterface *iface) const;
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index b5d45adadb..a593deb90e 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -876,6 +876,10 @@ void tst_QAccessibility::applicationTest()
QCOMPARE(interface->child(1), static_cast<QAccessibleInterface*>(0));
QCOMPARE(interface->childCount(), 0);
+ // Check that asking for the application interface twice returns the same object
+ QAccessibleInterface *app2 = QAccessible::queryAccessibleInterface(qApp);
+ QCOMPARE(interface, app2);
+
QWidget widget;
widget.show();
qApp->setActiveWindow(&widget);