diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-20 12:54:34 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-21 09:57:09 +0200 |
commit | 575ab78504c5082590970812e723ec01299787a2 (patch) | |
tree | 189d86d13883e2bf1fbebbb6be8258ad8a537b6c /vcl/qt5 | |
parent | ad4f75bdb49c28de626cce10da0bb7554a24681d (diff) |
qt a11y: Don't leak QAccessibleEvent
Create the `QAccessibleEvent`s passed to
`QAccessible::updateAccessibility` as local
stack variables instead of on the heap, to not leak
them, as `QAccessible::updateAccessibility` does
not take over ownership, i.e. doesn't delete them.
This is also what the example in the Qt doc [1]
does.
This fixes leaks reported by Valgrind, for example:
==104242== 416 bytes in 13 blocks are definitely lost in loss record 23,612 of 27,514
==104242== at 0x4840F83: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==104242== by 0x186F6884: QtAccessibleEventListener::HandleStateChangedEvent(QAccessibleInterface*, com::sun::star::accessibility::AccessibleEventObject const&) (QtAccessibleEventListener.cxx:144)
==104242== by 0x186F8478: QtAccessibleEventListener::notifyEvent(com::sun::star::accessibility::AccessibleEventObject const&) (QtAccessibleEventListener.cxx:401)
==104242== by 0x61B2756: comphelper::AccessibleEventNotifier::addEvent(unsigned int, com::sun::star::accessibility::AccessibleEventObject const&) (accessibleeventnotifier.cxx:256)
==104242== by 0x61ADB50: comphelper::OCommonAccessibleComponent::NotifyAccessibleEvent(short, com::sun::star::uno::Any const&, com::sun::star::uno::Any const&, int) (accessiblecomponenthelper.cxx:127)
==104242== by 0xBAA46FB: VCLXAccessibleComponent::ProcessWindowChildEvent(VclWindowEvent const&) (vclxaccessiblecomponent.cxx:173)
==104242== by 0xBAA4285: VCLXAccessibleComponent::WindowChildEventListener(VclWindowEvent&) (vclxaccessiblecomponent.cxx:124)
==104242== by 0xBAA3BBC: VCLXAccessibleComponent::LinkStubWindowChildEventListener(void*, VclWindowEvent&) (vclxaccessiblecomponent.cxx:114)
==104242== by 0xD56C687: Link<VclWindowEvent&, void>::Call(VclWindowEvent&) const (link.hxx:111)
==104242== by 0xD56977E: vcl::Window::CallEventListeners(VclEventId, void*) (event.cxx:296)
==104242== by 0xD6C83A1: vcl::Window::ImplSetReallyVisible() (window.cxx:1328)
==104242== by 0xD6C846C: vcl::Window::ImplSetReallyVisible() (window.cxx:1344)
[1] https://doc.qt.io/qt-6/accessible-qwidget.html
Change-Id: I82af810f0c618ffd5c5e4c8f568f4b4358df5900
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167862
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/qt5')
-rw-r--r-- | vcl/qt5/QtAccessibleEventListener.cxx | 170 |
1 files changed, 105 insertions, 65 deletions
diff --git a/vcl/qt5/QtAccessibleEventListener.cxx b/vcl/qt5/QtAccessibleEventListener.cxx index 4668e1585fba..ae79709fde86 100644 --- a/vcl/qt5/QtAccessibleEventListener.cxx +++ b/vcl/qt5/QtAccessibleEventListener.cxx @@ -140,8 +140,8 @@ void QtAccessibleEventListener::HandleStateChangedEvent( eEventType = QAccessible::ObjectShow; else eEventType = QAccessible::ObjectHide; - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, eEventType)); + QAccessibleEvent aEvent(pQAccessibleInterface, eEventType); + QAccessible::updateAccessibility(&aEvent); break; } // These don't seem to have a matching Qt equivalent @@ -160,8 +160,8 @@ void QtAccessibleEventListener::HandleStateChangedEvent( return; } - QAccessible::updateAccessibility( - new QAccessibleStateChangeEvent(pQAccessibleInterface, aState)); + QAccessibleStateChangeEvent aEvent(pQAccessibleInterface, aState); + QAccessible::updateAccessibility(&aEvent); } void QtAccessibleEventListener::notifyEvent(const css::accessibility::AccessibleEventObject& rEvent) @@ -171,17 +171,23 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible switch (rEvent.EventId) { case AccessibleEventId::NAME_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::NameChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::NameChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::DESCRIPTION_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::DescriptionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::DescriptionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::ACTION_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::ActionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::ActionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::ACTIVE_DESCENDANT_CHANGED: { // Qt has a QAccessible::ActiveDescendantChanged event type, but events of @@ -197,15 +203,16 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible QAccessibleInterface* pInterface = QAccessible::queryAccessibleInterface(pQtAcc); QAccessible::State aState; aState.focused = true; - QAccessible::updateAccessibility(new QAccessibleStateChangeEvent(pInterface, aState)); + QAccessibleStateChangeEvent aEvent(pInterface, aState); + QAccessible::updateAccessibility(&aEvent); return; } case AccessibleEventId::CARET_CHANGED: { sal_Int32 nNewCursorPos = 0; rEvent.NewValue >>= nNewCursorPos; - QAccessible::updateAccessibility( - new QAccessibleTextCursorEvent(pQAccessibleInterface, nNewCursorPos)); + QAccessibleTextCursorEvent aEvent(pQAccessibleInterface, nNewCursorPos); + QAccessible::updateAccessibility(&aEvent); return; } case AccessibleEventId::CHILD: @@ -218,8 +225,9 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible // tdf#159213 for now, workaround invalid events being sent and don't crash in release builds if (!xChild.is()) return; - QAccessible::updateAccessibility(new QAccessibleEvent( - QtAccessibleRegistry::getQObject(xChild), QAccessible::ObjectCreated)); + QAccessibleEvent aEvent(QtAccessibleRegistry::getQObject(xChild), + QAccessible::ObjectCreated); + QAccessible::updateAccessibility(&aEvent); return; } if (rEvent.OldValue >>= xChild) @@ -229,8 +237,9 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible // tdf#159213 for now, workaround invalid events being sent and don't crash in release builds if (!xChild.is()) return; - QAccessible::updateAccessibility(new QAccessibleEvent( - QtAccessibleRegistry::getQObject(xChild), QAccessible::ObjectDestroyed)); + QAccessibleEvent aEvent(QtAccessibleRegistry::getQObject(xChild), + QAccessible::ObjectDestroyed); + QAccessible::updateAccessibility(&aEvent); return; } SAL_WARN("vcl.qt", @@ -238,17 +247,23 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible return; } case AccessibleEventId::HYPERTEXT_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::HypertextChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::HypertextChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::SELECTION_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::Selection)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::Selection); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::VISIBLE_DATA_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::VisibleDataChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::VisibleDataChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TEXT_SELECTION_CHANGED: { QAccessibleTextInterface* pTextInterface = pQAccessibleInterface->textInterface(); @@ -261,44 +276,53 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible int nStartOffset = 0; int nEndOffset = 0; pTextInterface->selection(0, &nStartOffset, &nEndOffset); - QAccessible::updateAccessibility( - new QAccessibleTextSelectionEvent(pQAccessibleInterface, nStartOffset, nEndOffset)); + QAccessibleTextSelectionEvent aEvent(pQAccessibleInterface, nStartOffset, nEndOffset); + QAccessible::updateAccessibility(&aEvent); return; } case AccessibleEventId::TEXT_ATTRIBUTE_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::AttributeChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::AttributeChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TEXT_CHANGED: { TextSegment aDeletedText; TextSegment aInsertedText; if (rEvent.OldValue >>= aDeletedText) { - QAccessible::updateAccessibility( - new QAccessibleTextRemoveEvent(pQAccessibleInterface, aDeletedText.SegmentStart, - toQString(aDeletedText.SegmentText))); + QAccessibleTextRemoveEvent aEvent(pQAccessibleInterface, aDeletedText.SegmentStart, + toQString(aDeletedText.SegmentText)); + QAccessible::updateAccessibility(&aEvent); } if (rEvent.NewValue >>= aInsertedText) { - QAccessible::updateAccessibility(new QAccessibleTextInsertEvent( - pQAccessibleInterface, aInsertedText.SegmentStart, - toQString(aInsertedText.SegmentText))); + QAccessibleTextInsertEvent aEvent(pQAccessibleInterface, aInsertedText.SegmentStart, + toQString(aInsertedText.SegmentText)); + QAccessible::updateAccessibility(&aEvent); } return; } case AccessibleEventId::TABLE_CAPTION_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::TableCaptionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TableCaptionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TABLE_COLUMN_DESCRIPTION_CHANGED: - QAccessible::updateAccessibility(new QAccessibleEvent( - pQAccessibleInterface, QAccessible::TableColumnDescriptionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, + QAccessible::TableColumnDescriptionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TABLE_COLUMN_HEADER_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::TableColumnHeaderChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TableColumnHeaderChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TABLE_MODEL_CHANGED: { AccessibleTableModelChange aChange; @@ -326,27 +350,32 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible assert(false && "Unhandled AccessibleTableModelChangeType"); return; } - QAccessibleTableModelChangeEvent* pTableEvent - = new QAccessibleTableModelChangeEvent(pQAccessibleInterface, nType); - pTableEvent->setFirstRow(aChange.FirstRow); - pTableEvent->setLastRow(aChange.LastRow); - pTableEvent->setFirstColumn(aChange.FirstColumn); - pTableEvent->setLastColumn(aChange.LastColumn); - QAccessible::updateAccessibility(pTableEvent); + QAccessibleTableModelChangeEvent aTableEvent(pQAccessibleInterface, nType); + aTableEvent.setFirstRow(aChange.FirstRow); + aTableEvent.setLastRow(aChange.LastRow); + aTableEvent.setFirstColumn(aChange.FirstColumn); + aTableEvent.setLastColumn(aChange.LastColumn); + QAccessible::updateAccessibility(&aTableEvent); return; } case AccessibleEventId::TABLE_ROW_DESCRIPTION_CHANGED: - QAccessible::updateAccessibility(new QAccessibleEvent( - pQAccessibleInterface, QAccessible::TableRowDescriptionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TableRowDescriptionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TABLE_ROW_HEADER_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::TableRowHeaderChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TableRowHeaderChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::TABLE_SUMMARY_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::TableSummaryChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TableSummaryChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::SELECTION_CHANGED_ADD: case AccessibleEventId::SELECTION_CHANGED_REMOVE: { @@ -374,29 +403,40 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible // Qt expects the event to be sent for the (un)selected child QObject* pChildObject = QtAccessibleRegistry::getQObject(xChildAcc); assert(pChildObject); - QAccessible::updateAccessibility(new QAccessibleEvent(pChildObject, eEventType)); + QAccessibleEvent aEvent(pChildObject, eEventType); + QAccessible::updateAccessibility(&aEvent); return; } case AccessibleEventId::SELECTION_CHANGED_WITHIN: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::SelectionWithin)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::SelectionWithin); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::PAGE_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::PageChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::PageChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::SECTION_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::SectionChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::SectionChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::COLUMN_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::TextColumnChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::TextColumnChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::BOUNDRECT_CHANGED: - QAccessible::updateAccessibility( - new QAccessibleEvent(pQAccessibleInterface, QAccessible::LocationChanged)); + { + QAccessibleEvent aEvent(pQAccessibleInterface, QAccessible::LocationChanged); + QAccessible::updateAccessibility(&aEvent); return; + } case AccessibleEventId::STATE_CHANGED: HandleStateChangedEvent(pQAccessibleInterface, rEvent); return; @@ -406,8 +446,8 @@ void QtAccessibleEventListener::notifyEvent(const css::accessibility::Accessible if (pValueInterface) { const QVariant aValue = pValueInterface->currentValue(); - QAccessible::updateAccessibility( - new QAccessibleValueChangeEvent(pQAccessibleInterface, aValue)); + QAccessibleValueChangeEvent aEvent(pQAccessibleInterface, aValue); + QAccessible::updateAccessibility(&aEvent); } return; } |