Visitar URL original
fix: dangling WebContents/NativeWindow pointers in debugger, devtools, login, modal and process-reuse paths by MarshallOfSound · Pull Request #53287 · electron/electron · GitHub
Skip to content

fix: dangling WebContents/NativeWindow pointers in debugger, devtools, login, modal and process-reuse paths - #53287

Merged
MarshallOfSound merged 5 commits into
44-x-yfrom
bp/44-x-y/53257
Aug 28, 2026
Merged

MarshallOfSound merged 5 commits into
44-x-yfrom
bp/44-x-y/53257

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Backport of #53257

See that PR for details.

Notes: Fixed crashes when a webContents or parent window is destroyed while other APIs still reference it.

…destroyed webContents

The Debugger held its own raw pointer to the content::WebContents alongside
the WebContentsObserver base, and that copy was never cleared when the
WebContents went away. Calling attach() after webContents.destroy() then
handed a freed pointer to DevToolsAgentHost::GetOrCreateFor.

Drop the duplicate member and use WebContentsObserver::web_contents(), which
is reset on destruction, so attach() now throws "No target available".

(cherry picked from commit 74bf5c0)
…t is destroyed

InspectableWebContents only starts observing the externally supplied
devtools WebContents once ShowDevTools() runs, so if that WebContents was
destroyed between setDevToolsWebContents() and openDevTools() the stored
raw pointer dangled and ShowDevTools() observed and navigated freed memory.

Hold the external devtools WebContents as a base::WeakPtr so it reads as
null once destroyed, in which case we fall back to the built-in devtools
window exactly as if none had been assigned.

(cherry picked from commit 9e4a9b8)
…d webContents

ElectronBrowserClient remembers which WebContents most recently claimed each
pending renderer process so AppendExtraCommandLineSwitches can find its
preferences. The map held raw WebContents pointers and was only pruned when
the RenderProcessHost itself was destroyed, so when two webContents shared a
process and the registrant was destroyed, re-initialising that process (for
example to start a service worker) read the freed WebContents.

Store base::WeakPtr<content::WebContents> in the map and fall back to the
live-WebContents lookup when the entry has gone away.

(cherry picked from commit 28ff3a9)
…ge is pending

LoginHandler posts a task to emit the 'login' event and bound the raw
content::WebContents pointer into it. If the WebContents was destroyed
between the auth challenge arriving and that task running, EmitEvent looked
up api::WebContents from a freed pointer.

Bind a base::WeakPtr to the WebContents instead and cancel the auth request
when it has gone away, matching what we already do when the JS wrapper is
gone.

(cherry picked from commit fdfd411)
…destroyed

NativeWindow stored its parent as a raw pointer with a comment claiming the
parent outlives the child, but nothing enforces that: destroy()ing the
parent leaves the child alive, and the next hide()/show() on a modal child
called into the freed parent to update its modal-child count.

Hold the parent as a base::WeakPtr<NativeWindow> so parent() returns null
once the parent window is gone and those paths become no-ops.

(cherry picked from commit e7881de)
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) August 28, 2026 23:12
@MarshallOfSound
MarshallOfSound merged commit 9d3f4ff into 44-x-y Aug 28, 2026
90 checks passed
@MarshallOfSound
MarshallOfSound deleted the bp/44-x-y/53257 branch August 28, 2026 23:48
@release-clerk

release-clerk Bot commented Aug 28, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed crashes when a webContents or parent window is destroyed while other APIs still reference it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

44-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants