Repository navigation
fix: dangling rawptr NativeWindow::primary_web_contents_view_ - #52546
Merged
Merged
Conversation
NativeWindow does not own the BrowserWindow's inspectable view, so its raw pointer could outlive the view during WebContents teardown. Track the Views lifetime instead of requiring each destruction path to clear the pointer.
deepak1556
reviewed
Jul 30, 2026
refactor: remove NativeWindow::primary_web_contents_view_initialized_
deepak1556
approved these changes
Jul 30, 2026
jkleinsc
approved these changes
Jul 30, 2026
|
No Release Notes |
Contributor
|
I was unable to backport this PR to "43-x-y" cleanly; |
Contributor
|
I have automatically backported this PR to "44-x-y", please check out #52570 |
This was referenced Aug 18, 2026
Contributor
|
@VerteDinde has manually backported this PR to "43-x-y", please check out #52939 |
MarshallOfSound
pushed a commit
that referenced
this pull request
Aug 18, 2026
fix: dangling rawptr `NativeWindow::primary_web_contents_view_` (#52546) * fix: track the primary web contents view NativeWindow does not own the BrowserWindow's inspectable view, so its raw pointer could outlive the view during WebContents teardown. Track the Views lifetime instead of requiring each destruction path to clear the pointer. * fixup! fix: track the primary web contents view refactor: remove NativeWindow::primary_web_contents_view_initialized_ (cherry picked from commit bbb00d1) Co-authored-by: Charles Kerr <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Fix a dangling raw_ptr in
NativeWindow::primary_web_contents_view_after theelectron::api::WebContentswas destroyed.When looking at this, I noticed that
NativeWindow::set_primary_web_contents_view()was used for only two things: (1) initializing the value on startup (one callsite) (2) clearing the value when the WebContentsView was being torn down (two callsites). Following that pattern, the fix for this crash would be to add a thirdset_rimary_web_contents_view(nullptr)call, this time inWebContents::~WebContents().This duplicated manual pointer management is a code smell. Instead of adding a third call, I've removed the method and changed the field's type so that
ui::Viewscan track the view's lifecycle for us:The rawptr bug that this fixes was showing up in:
default behavior window-all-closed quits when the app does not handle the eventdefault behavior window-all-closed does not quit when the app handles the eventand the crash was:
Checklist
npm testpassesRelease Notes
Notes: none.