Bug 314583

Summary: [BFCache] CachedPage::restore() leaks cached frame state when focus restoration is skipped
Product: WebKit Reporter: Basuke Suzuki <basuke>
Component: WebCore Misc.Assignee: Basuke Suzuki <basuke>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Basuke Suzuki
Reported 2026-05-11 14:41:36 PDT
CachedPage::restore() has an early-return at `if (!focusedOrMainFrame) return;` that bypasses the `clear()` call at the end of the function. The cached frame state (m_cachedMainFrame holding CachedFrames with documents/views) is never released, even though the cached page's data has already been transferred to the live page by `m_cachedMainFrame->open()`. This causes ~CachedPage to call `m_cachedMainFrame->destroy()` later. After the fix in bug 314238 (which destroys child CachedFrames before checking m_document), destroy() now descends into child CachedFrames whose documents have already been resumed by open() (state = NotInBackForwardCache). The ASSERT at CachedFrame.cpp:291 ASSERT(document->backForwardCacheState() == Document::InBackForwardCache); then fires, and the subsequent destroy code path corrupts live document state (detachViewsAndDocumentLoader, detachFromPage, removeAllEventListeners), hanging the WebContent process. The early-return path is reached when `page.focusController().focusedOrMainFrame()` returns null, which happens for iframe-process BFCache restoration where the page's main frame is a RemoteFrame and there is no LocalFrame to focus. Fix: call `clear()` in the early-return branch to release the cached frame state, since `open()` has already done its work and the cached storage is no longer needed.
Attachments
Basuke Suzuki
Comment 1 2026-05-11 14:50:15 PDT
Tracked in rdar://176824162
Basuke Suzuki
Comment 2 2026-05-11 16:05:46 PDT
Basuke Suzuki
Comment 3 2026-05-11 16:06:15 PDT
EWS
Comment 4 2026-05-11 17:45:13 PDT
Committed 313043@main (11ea56301070): <https://commits.webkit.org/313043@main> Reviewed commits have been landed. Closing PR #64708 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.