<?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>118268</bug_id>
          
          <creation_ts>2013-07-01 17:39:13 -0700</creation_ts>
          <short_desc>Crash in PageBanner::detachFromPage() when called from ~WebPage()</short_desc>
          <delta_ts>2013-07-02 12:54:27 -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>Layout and Rendering</component>
          <version>528+ (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></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ada Chan">adachan</reporter>
          <assigned_to name="Ada Chan">adachan</assigned_to>
          <cc>bdakin</cc>
    
    <cc>sam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>905182</commentid>
    <comment_count>0</comment_count>
    <who name="Ada Chan">adachan</who>
    <bug_when>2013-07-01 17:39:13 -0700</bug_when>
    <thetext>The crash log looks like this:


Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   com.apple.WebCore             	0x0000000102e1443d WebCore::Page::addHeaderWithHeight(int) + 13 (Page.cpp:1309)
1   com.apple.WebKit2             	0x000000010195ee08 WebKit::PageBanner::detachFromPage() + 74 (PageBannerMac.mm:87)
2   com.apple.WebKit2             	0x00000001019eedc4 WebKit::WebPage::~WebPage() + 188 (RefPtr.h:76)
3   com.apple.WebKit2             	0x00000001019eeca9 WebKit::WebPage::~WebPage() + 17 (ThreadSafeRefCounted.h:72)
4   com.apple.WebKit2             	0x0000000101a455f9 WTF::HashTable&lt;unsigned long long, WTF::KeyValuePair&lt;unsigned long long, WTF::RefPtr&lt;WebKit::WebPage&gt; &gt;, WTF::KeyValuePairKeyExtractor&lt;WTF::KeyValuePair&lt;unsigned long long, WTF::RefPtr&lt;WebKit::WebPage&gt; &gt; &gt;, WTF::IntHash&lt;unsigned long long&gt;, WTF::HashMapValueTraits&lt;WTF::HashTraits&lt;unsigned long long&gt;, WTF::HashTraits&lt;WTF::RefPtr&lt;WebKit::WebPage&gt; &gt; &gt;, WTF::HashTraits&lt;unsigned long long&gt; &gt;::remove(WTF::KeyValuePair&lt;unsigned long long, WTF::RefPtr&lt;WebKit::WebPage&gt; &gt;*) + 31 (HashTraits.h:62)
5   com.apple.WebKit2             	0x0000000101a41d89 WebKit::WebProcess::removeWebPage(unsigned long long) + 37 (WebProcess.cpp:593)
6   com.apple.WebKit2             	0x00000001019efd18 WebKit::WebPage::close() + 466 (WebPage.cpp:867)
7   com.apple.WebKit2             	0x00000001019372c1 CoreIPC::MessageReceiverMap::dispatchMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&amp;) + 137 (MessageReceiverMap.cpp:86)
8   com.apple.WebKit2             	0x0000000101a41eb2 WebKit::WebProcess::didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&amp;) + 34 (WebProcess.cpp:637)
9   com.apple.WebKit2             	0x000000010190ac37 CoreIPC::Connection::dispatchMessage(WTF::PassOwnPtr&lt;CoreIPC::MessageDecoder&gt;) + 105 (ArgumentDecoder.h:47)
10  com.apple.WebKit2             	0x000000010190c694 CoreIPC::Connection::dispatchOneMessage() + 96 (PassOwnPtr.h:59)
11  com.apple.WebCore             	0x0000000102fd64ae WebCore::RunLoop::performWork() + 254 (Functional.h:704)
12  com.apple.WebCore             	0x0000000102fd69b2 WebCore::RunLoop::performWork(void*) + 34 (RunLoopCF.cpp:39)
13  com.apple.CoreFoundation      	0x00007fff92a41b31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14  com.apple.CoreFoundation      	0x00007fff92a41455 __CFRunLoopDoSources0 + 245
15  com.apple.CoreFoundation      	0x00007fff92a647f5 __CFRunLoopRun + 789
16  com.apple.CoreFoundation      	0x00007fff92a640e2 CFRunLoopRunSpecific + 290
17  com.apple.HIToolbox           	0x00007fff97aa7eb4 RunCurrentEventLoopInMode + 209
18  com.apple.HIToolbox           	0x00007fff97aa7c52 ReceiveNextEventCommon + 356
19  com.apple.HIToolbox           	0x00007fff97aa7ae3 BlockUntilNextEventMatchingListInMode + 62
20  com.apple.AppKit              	0x00007fff966be533 _DPSNextEvent + 685
21  com.apple.AppKit              	0x00007fff966bddf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
22  com.apple.AppKit              	0x00007fff966b51a3 -[NSApplication run] + 517
23  com.apple.WebCore             	0x0000000102fd7032 WebCore::RunLoop::run() + 82 (RunLoopMac.mm:43)
24  com.apple.WebKit2             	0x00000001019af97b int WebKit::ChildProcessMain&lt;WebKit::WebProcess, WebKit::WebContentProcessMainDelegate&gt;(int, char**) + 579 (ChildProcessEntryPoint.h:100)
25  com.apple.WebProcess          	0x00000001018c0e23 main + 337 (ChildProcessMain.mm:83)
26  libdyld.dylib                 	0x00007fff8c8a27e1 start + 1

Looks like m_webPage-&gt;corePage() is null.

Proposed fix is to add a null check:

void PageBanner::detachFromPage()
{
    // We can hide the banner by removing the parent layer that hosts it.
    if (m_webPage &amp;&amp; m_webPage-&gt;corePage()) {
        if (m_type == Header)
            m_webPage-&gt;corePage()-&gt;addHeaderWithHeight(0);
        else if (m_type == Footer)
            m_webPage-&gt;corePage()-&gt;addFooterWithHeight(0);
    }

    m_type = NotSet;
    m_webPage = 0;
}

Beth, Sam: what do you think?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905213</commentid>
    <comment_count>1</comment_count>
    <who name="Beth Dakin">bdakin</who>
    <bug_when>2013-07-01 19:11:00 -0700</bug_when>
    <thetext>I think it would be just slightly better to return early in this function if there is no WebPage. Something like:

void PageBanner::detachFromPage()
{
    // Comment about how it is possible that the banner has already detached from the page by explicitly being set to null.
    if (!m_webPage)
        return;

    // We can hide the banner by removing the parent layer that hosts it.
    if ( m_webPage-&gt;corePage()) {
        if (m_type == Header)
            m_webPage-&gt;corePage()-&gt;addHeaderWithHeight(0);
        else if (m_type == Footer)
            m_webPage-&gt;corePage()-&gt;addFooterWithHeight(0);
    }

    m_type = NotSet;
    m_webPage = 0;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905221</commentid>
    <comment_count>2</comment_count>
    <who name="Ada Chan">adachan</who>
    <bug_when>2013-07-01 19:51:58 -0700</bug_when>
    <thetext>(In reply to comment #1)
&gt; I think it would be just slightly better to return early in this function if there is no WebPage. Something like:
&gt; 
&gt; void PageBanner::detachFromPage()
&gt; {
&gt;     // Comment about how it is possible that the banner has already detached from the page by explicitly being set to null.

I&apos;m actually not sure how it is possible that we get into the situation where m_webPage is 0. In the case of this crash, m_webPage is non-null, but m_webPage-&gt;corePage() is because by the time ~WebPage() is called, WebPage::close() has been called and WebPage::m_page has been set to null.

&gt;     if (!m_webPage)
&gt;         return;
&gt; 
&gt;     // We can hide the banner by removing the parent layer that hosts it.
&gt;     if ( m_webPage-&gt;corePage()) {
&gt;         if (m_type == Header)
&gt;             m_webPage-&gt;corePage()-&gt;addHeaderWithHeight(0);
&gt;         else if (m_type == Footer)
&gt;             m_webPage-&gt;corePage()-&gt;addFooterWithHeight(0);
&gt;     }
&gt; 
&gt;     m_type = NotSet;
&gt;     m_webPage = 0;
&gt; }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905223</commentid>
    <comment_count>3</comment_count>
      <attachid>205857</attachid>
    <who name="Ada Chan">adachan</who>
    <bug_when>2013-07-01 19:59:41 -0700</bug_when>
    <thetext>Created attachment 205857
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905496</commentid>
    <comment_count>4</comment_count>
      <attachid>205857</attachid>
    <who name="Beth Dakin">bdakin</who>
    <bug_when>2013-07-02 11:04:32 -0700</bug_when>
    <thetext>Comment on attachment 205857
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=205857&amp;action=review

&gt; Source/WebKit2/WebProcess/WebPage/mac/PageBannerMac.mm:84
&gt; +    if (!m_webPage)

I think we should make this:

if (!m_webPage || !m_webPage-&gt;corePage())
    return;

And you can put your comment up there too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905534</commentid>
    <comment_count>5</comment_count>
      <attachid>205857</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2013-07-02 12:13:54 -0700</bug_when>
    <thetext>Comment on attachment 205857
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=205857&amp;action=review

&gt;&gt; Source/WebKit2/WebProcess/WebPage/mac/PageBannerMac.mm:84
&gt;&gt; +    if (!m_webPage)
&gt; 
&gt; I think we should make this:
&gt; 
&gt; if (!m_webPage || !m_webPage-&gt;corePage())
&gt;     return;
&gt; 
&gt; And you can put your comment up there too.

But don’t we want to set m_type to NotSet and m_webPage to 0 even if m_webPage-&gt;corePage() is 0?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905537</commentid>
    <comment_count>6</comment_count>
    <who name="Beth Dakin">bdakin</who>
    <bug_when>2013-07-02 12:16:10 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; (From update of attachment 205857 [details])
&gt; View in context: https://bugs.webkit.org/attachment.cgi?id=205857&amp;action=review
&gt; 
&gt; &gt;&gt; Source/WebKit2/WebProcess/WebPage/mac/PageBannerMac.mm:84
&gt; &gt;&gt; +    if (!m_webPage)
&gt; &gt; 
&gt; &gt; I think we should make this:
&gt; &gt; 
&gt; &gt; if (!m_webPage || !m_webPage-&gt;corePage())
&gt; &gt;     return;
&gt; &gt; 
&gt; &gt; And you can put your comment up there too.
&gt; 
&gt; But don’t we want to set m_type to NotSet and m_webPage to 0 even if m_webPage-&gt;corePage() is 0?

Oh right. Yes. I forgot that my theory that this was happening because PageBanner::detachFromPage() had already been called was false. In this case, I think your patch is fine as-is, Ada.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>905554</commentid>
    <comment_count>7</comment_count>
    <who name="Ada Chan">adachan</who>
    <bug_when>2013-07-02 12:54:27 -0700</bug_when>
    <thetext>Thanks Beth and Darin for your comments!

Committed:
https://trac.webkit.org/changeset/152316</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>205857</attachid>
            <date>2013-07-01 19:59:41 -0700</date>
            <delta_ts>2013-07-02 12:16:37 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>0001-Fix-crash-when-PageBanner-detachFromPage-is-called-f.patch</filename>
            <type>text/plain</type>
            <size>2643</size>
            <attacher name="Ada Chan">adachan</attacher>
            
              <data encoding="base64">RnJvbSAzMDYzMWNjNTRiN2UzODk3NWQ4YjBkMWE5YTE2YjUzNDNmZDgwYWUwIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBBZGEgQ2hhbiA8YWRhY2hhbkBhcHBsZS5jb20+CkRhdGU6IE1v
biwgMSBKdWwgMjAxMyAxOTo1Njo0NyAtMDcwMApTdWJqZWN0OiBbUEFUQ0hdIEZpeCBjcmFzaCB3
aGVuIFBhZ2VCYW5uZXI6OmRldGFjaEZyb21QYWdlKCkgaXMgY2FsbGVkIGZyb20KIFdlYlBhZ2U6
On5XZWJQYWdlKCkuIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xMTgy
NjgKClJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgoKKiBXZWJQcm9jZXNzL1dlYlBhZ2UvbWFj
L1BhZ2VCYW5uZXJNYWMubW06CihXZWJLaXQ6OlBhZ2VCYW5uZXI6OmRldGF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ICBtX3dlYlBhZ2UtPmNvcmVQYWdlKCktPmFkZEhlYWRlcldpdGhI
ZWlnaHQoMCk7Ci0gICAgZWxzZSBpZiAobV90eXBlID09IEZvb3RlcikKLSAgICAgICAgbV93ZWJQ
YWdlLT5jb3JlUGFnZSgpLT5hZGRGb290ZXJXaXRoSGVpZ2h0KDApOworICAgIGlmICghbV93ZWJQ
YWdlKQorICAgICAgICByZXR1cm47CisKKyAgICAvLyBtX3dlYlBhZ2UtPmNvcmVQYWdlKCkgY2Fu
IGJlIG51bGwgd2hlbiB0aGlzIGlzIGNhbGxlZCBmcm9tIFdlYlBhZ2U6On5XZWJQYWdlKCkgYWZ0
ZXIKKyAgICAvLyB0aGUgd2ViIHBhZ2UgaGFzIGJlZW4gY2xvc2VkLgorICAgIGlmIChtX3dlYlBh
Z2UtPmNvcmVQYWdlKCkpIHsKKyAgICAgICAgLy8gV2UgY2FuIGhpZGUgdGhlIGJhbm5lciBieSBy
ZW1vdmluZyB0aGUgcGFyZW50IGxheWVyIHRoYXQgaG9zdHMgaXQuCisgICAgICAgIGlmIChtX3R5
cGUgPT0gSGVhZGVyKQorICAgICAgICAgICAgbV93ZWJQYWdlLT5jb3JlUGFnZSgpLT5hZGRIZWFk
ZXJXaXRoSGVpZ2h0KDApOworICAgICAgICBlbHNlIGlmIChtX3R5cGUgPT0gRm9vdGVyKQorICAg
ICAgICAgICAgbV93ZWJQYWdlLT5jb3JlUGFnZSgpLT5hZGRGb290ZXJXaXRoSGVpZ2h0KDApOwor
ICAgIH0KIAogICAgIG1fdHlwZSA9IE5vdFNldDsKICAgICBtX3dlYlBhZ2UgPSAwOwotLSAKMS44
LjIuMSAoQXBwbGUgR2l0LTQ1KQoK
</data>
<flag name="review"
          id="227475"
          type_id="1"
          status="+"
          setter="bdakin"
    />
          </attachment>
      

    </bug>

</bugzilla>