Skip to content

Fix memory leak in _getIA2TargetsForRelationsOfType.#20207

Merged
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:free
May 25, 2026
Merged

Fix memory leak in _getIA2TargetsForRelationsOfType.#20207
seanbudd merged 1 commit into
nvaccess:masterfrom
jcsteh:free

Conversation

@jcsteh

@jcsteh jcsteh commented May 24, 2026

Copy link
Copy Markdown
Contributor

Link to issue number:

None.

Summary of the issue:

NVDAObjects.IAccessible.IAccessible._getIA2TargetsForRelationsOfType calls IAccessible2_2::relationTargetsOfType, a COM method which returns a server-allocated array. Per COM rules and the IAccessible2 documentation, this array must be freed with CoTaskMemFree. However, comtypes doesn't have sufficient information to know that it must be freed, nor do we explicitly free it ourselves. Thus, we are leaking memory every time we call this and it returns a relation.

Note that we already call CoTaskMemFree for IAccessibleTableCell::row/columnHeaderCells, which is a similar COM method. See NVDAObjects.IAccessible.IAccessible._tableHeaderTextHelper.

Description of user facing changes:

Fixes a memory leak. However, I don't think this is worth noting in the What's New, since it's probably not significant enough for most users to notice.

Description of development approach:

Use try/finally after the COM method call. Call CoTaskMemFree in the finally block.

Testing strategy:

  1. Used this test case in Microsoft Edge:
    data:text/html,<button aria-details="d">b</button><div id="d">d
  2. Switched to focus mode.
  3. Tabbed to the button.
  4. Repeatedly pressed NVDA+d. It reported "d" as expected each time.

Note that this can't currently be tested in Firefox, as NVDA details reporting is broken in focus mode in Firefox. However, that is an existing bug, not one introduced by this PR.

Known issues with pull request:

None.

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • Security precautions taken.

@jcsteh jcsteh requested a review from a team as a code owner May 24, 2026 23:50
@jcsteh jcsteh requested a review from SaschaCowley May 24, 2026 23:50

@seanbudd seanbudd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

@seanbudd seanbudd merged commit dd1bfe8 into nvaccess:master May 25, 2026
40 of 42 checks passed
@github-actions github-actions Bot added this to the 2026.3 milestone May 25, 2026
@jcsteh jcsteh deleted the free branch May 25, 2026 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants