<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>314583</bug_id>
          
          <creation_ts>2026-05-11 14:41:36 -0700</creation_ts>
          <short_desc>[BFCache] CachedPage::restore() leaks cached frame state when focus restoration is skipped</short_desc>
          <delta_ts>2026-05-11 17:45:15 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Basuke Suzuki">basuke</reporter>
          <assigned_to name="Basuke Suzuki">basuke</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2209852</commentid>
    <comment_count>0</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2026-05-11 14:41:36 -0700</bug_when>
    <thetext>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&apos;s data has already been transferred to
the live page by `m_cachedMainFrame-&gt;open()`.

This causes ~CachedPage to call `m_cachedMainFrame-&gt;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-&gt;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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209857</commentid>
    <comment_count>1</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2026-05-11 14:50:15 -0700</bug_when>
    <thetext>Tracked in rdar://176824162</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209891</commentid>
    <comment_count>2</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2026-05-11 16:05:46 -0700</bug_when>
    <thetext>&lt;rdar://problem/176824162&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209892</commentid>
    <comment_count>3</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2026-05-11 16:06:15 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/64708</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2209926</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-05-11 17:45:13 -0700</bug_when>
    <thetext>Committed 313043@main (11ea56301070): &lt;https://commits.webkit.org/313043@main&gt;

Reviewed commits have been landed. Closing PR #64708 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>