Fix memory leak in _getIA2TargetsForRelationsOfType. (#20207)
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:
Used this test case in Microsoft Edge:
data:text/html,<button aria-details="d">b</button><div id="d">d
Switched to focus mode.
Tabbed to the button.
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.