Skip to content

fix: several small memory leaks in Windows code - #53853

Merged
MarshallOfSound merged 3 commits into
mainfrom
fix/com-reference-leaks
Sep 12, 2026
Merged

MarshallOfSound merged 3 commits into
mainfrom
fix/com-reference-leaks

Conversation

@dsanders11

Copy link
Copy Markdown
Member

Description of Change

Fixes several small memory leaks due to leaking COM references in Windows code.

Checklist

Release Notes

Notes: Fixed a memory leak on Windows when app.getPreferredSystemLanguages() was called.
Notes: Fixed a memory leak on Windows when selecting multiple files in an open dialog.
Notes: Fixed a memory leak on Windows when notification initialization was retried after a failure.

@dsanders11 dsanders11 added semver/patch backwards-compatible bug fixes target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 12, 2026
@MarshallOfSound

Copy link
Copy Markdown
Member

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good — three small, correct COM smart-pointer leak fixes on Windows-only code.

What was reviewed: the ReleaseAndGetAddressOf() swaps in windows_toast_notification.cc (releases any prior toast_manager_/toast_notifier_ reference before the factory writes a new one); the CComPtr<IShellItem> item move into the loop body in file_dialog_win.cc (each iteration now gets a fresh smart pointer whose destructor releases before the next GetItemAt call, rather than reusing one item via raw &item across iterations); and the raw IVectorView<HSTRING>* to Microsoft::WRL::ComPtr<...> change in language_util_win.cc, confirming downstream uses (get_Size, GetAt) still work unchanged through operator->.

Extended reasoning...

Overview

This PR touches three Windows-only C++ files: shell/browser/notifications/win/windows_toast_notification.cc, shell/browser/ui/file_dialog_win.cc, and shell/common/language_util_win.cc. All three changes correct COM/WRL smart-pointer usage bugs that cause reference leaks: (1) using GetAddressOf() instead of ReleaseAndGetAddressOf() when re-populating a ComPtr that may already hold a reference, (2) reusing a single CComPtr<IShellItem> across loop iterations without releasing the prior reference, and (3) using a raw, never-released IVectorView<HSTRING>* instead of a ComPtr.

Security risks

None. These are internal resource-management (reference-counting) fixes with no new external input handling, no IPC surface, no sandbox/context-isolation implications, and no public API change. Worst-case impact of the pre-existing bugs was a handle/reference leak, not memory corruption or a security boundary issue.

Level of scrutiny

I traced each change against its surrounding code (read the full Initialize() function, the file-dialog loop, and the language-preferences function) and confirmed each fix is mechanically correct and doesn't change control flow or introduce new failure paths: ReleaseAndGetAddressOf() is the standard WRL idiom for this exact scenario; moving the CComPtr declaration inside the loop is the standard ATL idiom to force a release each iteration; and the ComPtr wrapper for langs is used identically to the raw pointer via operator-> for the two subsequent calls (get_Size, GetAt), so no follow-on Release() call was dropped. The change is small, self-contained, follows well-established COM/ATL/WRL patterns, and does not touch security-sensitive or cross-process code paths, so I judge this at the low end of required scrutiny.

Other factors

The PR is Windows-specific and not something CI can meaningfully exercise for the leak itself (these are resource-leak fixes, not behavior-visible bugs), which matches the checklist author's claim of manual build/test verification. There is a maintainer comment in the timeline after the last commit, but with no visible content or explicit CHANGES_REQUESTED/unresolved-thread state, and my own read of the current diff, I found nothing incorrect or unaddressed to flag. No CODEOWNERS restriction is evident on these paths, and the change is small enough that I'm confident a human need not scrutinize it further.

@dsanders11
dsanders11 marked this pull request as ready for review September 12, 2026 21:06
@MarshallOfSound
MarshallOfSound merged commit bcbc3eb into main Sep 12, 2026
155 of 157 checks passed
@MarshallOfSound
MarshallOfSound deleted the fix/com-reference-leaks branch September 12, 2026 23:31
@release-clerk

release-clerk Bot commented Sep 12, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a memory leak on Windows when app.getPreferredSystemLanguages() was called.

@trop

trop Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #53867

@trop

trop Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #53868

@trop trop Bot added in-flight/43-x-y in-flight/44-x-y and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. labels Sep 12, 2026
@trop

trop Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "45-x-y", please check out #53869

@trop trop Bot added in-flight/45-x-y merged/44-x-y PR was merged to the "44-x-y" branch. and removed target/45-x-y PR should also be added to the "45-x-y" branch. in-flight/44-x-y in-flight/45-x-y labels Sep 12, 2026
@trop trop Bot added merged/45-x-y PR was merged to the "45-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. and removed in-flight/43-x-y labels Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/45-x-y PR was merged to the "45-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants