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>
bb10
Frederik Gladhorn 2017-10-27 10:53:51 +02:00
parent 10b3286313
commit 1e9da7b3fd
3 changed files with 11 additions and 0 deletions

View File

@ -57,6 +57,12 @@ static void cleanupAccessibleCache()
accessibleCache = nullptr;
}
QAccessibleCache::~QAccessibleCache()
{
for (QAccessibleInterface *iface: idToInterface.values())
delete iface;
}
QAccessibleCache *QAccessibleCache::instance()
{
if (!accessibleCache) {

View File

@ -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;

View File

@ -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);