<?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>21329</bug_id>
          
          <creation_ts>2008-10-03 01:05:22 -0700</creation_ts>
          <short_desc>REGRESSION: crash in ScriptElement::notifyFinished</short_desc>
          <delta_ts>2008-10-06 06:08:01 -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>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows XP</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.kino.de/kinosuche.php4</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Darin Fisher (:fishd, Google)">fishd</reporter>
          <assigned_to name="Darin Fisher (:fishd, Google)">fishd</assigned_to>
          <cc>ap</cc>
    
    <cc>eric</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>93865</commentid>
    <comment_count>0</comment_count>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-10-03 01:05:22 -0700</bug_when>
    <thetext>REGRESSION: crash in ScriptElement::notifyFinished

I observed this crash on http://www.kino.de/kinosuche.php4
(you might have to load that site a couple times to repro the crash)

I found that some code changed recently that probably explains the crash.

Compare:

-void HTMLScriptElement::notifyFinished(CachedResource* o)
-{
-    CachedScript* cs = static_cast&lt;CachedScript*&gt;(o);
-
-    ASSERT(cs == m_cachedScript);
-
-    // Evaluating the script could lead to a garbage collection which
-    // can delete the script element so we need to protect it.
-    RefPtr&lt;HTMLScriptElement&gt; protect(this);
-    
-    if (cs-&gt;errorOccurred())
-        dispatchHTMLEvent(errorEvent, true, false);
-    else {
-        evaluateScript(cs-&gt;url(), cs-&gt;script());
-        dispatchHTMLEvent(loadEvent, false, false);
-    }
-
-    // script evaluation may have dereffed it already
-    if (m_cachedScript) {
-        m_cachedScript-&gt;removeClient(this);
-        m_cachedScript = 0;
-    }
-}

To:

void ScriptElementData::notifyFinished(CachedResource* o)
{
    CachedScript* cs = static_cast&lt;CachedScript*&gt;(o);
    ASSERT(cs == m_cachedScript);

    if (cs-&gt;errorOccurred())
        m_scriptElement-&gt;dispatchErrorEvent();
    else {
        RefPtr&lt;Element&gt; protector(m_element);
        evaluateScript(cs-&gt;url(), cs-&gt;script());
        m_scriptElement-&gt;dispatchLoadEvent();
    }

    stopLoadRequest();
}

The crash I get is inside stopLoadRequest() with |this| having been trashed.  m_element owns |this|.

Here&apos;s the interesting portion of the crash stack:

 	chrome.dll!WTF::HashTable&lt;WebCore::RenderObject *,std::pair&lt;WebCore::RenderObject *,WebCore::RenderBlock::FloatingObject 
*&gt;,WTF::PairFirstExtractor&lt;std::pair&lt;WebCore::RenderObject *,WebCore::RenderBlock::FloatingObject *&gt; &gt;,WTF::PtrHash&lt;WebCore::RenderObject 
*&gt;,WTF::PairHashTraits&lt;WTF::HashTraits&lt;WebCore::RenderObject *&gt;,WTF::HashTraits&lt;WebCore::RenderBlock::FloatingObject *&gt; 
&gt;,WTF::HashTraits&lt;WebCore::RenderObject *&gt; &gt;::find&lt;WebCore::RenderObject *,WTF::IdentityHashTranslator&lt;WebCore::RenderObject 
*,std::pair&lt;WebCore::RenderObject *,WebCore::RenderBlock::FloatingObject *&gt;,WTF::PtrHash&lt;WebCore::RenderObject *&gt; &gt; &gt;(WebCore::RenderObject * const &amp; 
key=0x0232775c)  Line 751	C++
 	chrome.dll!WebCore::CachedResource::removeClient(WebCore::CachedResourceClient * c=0x0232775c)  Line 131 + 0x12 bytes	C++
&gt;	chrome.dll!WebCore::ScriptElementData::notifyFinished(WebCore::CachedResource * o=0x02330e58)  Line 191 + 0xd bytes	C++
 	chrome.dll!WebCore::CachedScript::checkNotify()  Line 95 + 0xa bytes	C++
 	chrome.dll!WebCore::CachedScript::data(WTF::PassRefPtr&lt;WebCore::SharedBuffer&gt; data={...}, bool allDataReceived=true)  Line 85 + 0xe bytes	
C++
 	chrome.dll!WebCore::Loader::Host::didFinishLoading(WebCore::SubresourceLoader * loader=0x034297f8)  Line 278	C++
 	chrome.dll!WebCore::SubresourceLoader::didFinishLoading()  Line 195	C++
 	chrome.dll!WebCore::ResourceLoader::didFinishLoading(WebCore::ResourceHandle * __formal=0x01f31cf8)  Line 399	C++

Originally identified here:
http://code.google.com/p/chromium/issues/detail?id=3056

In the old code, the protector was also ensuring that |this| remained valid until after stopLoadRequest() is called.  I think this is an apparent goof in the recent code change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93869</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-10-03 01:11:31 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; I found that some code changed recently that probably explains the crash.

&lt;http://trac.webkit.org/changeset/35744&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93871</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-10-03 01:16:13 -0700</bug_when>
    <thetext>This patch, which essentially just rolls back part of the original change, seems to resolve the bug.  I&apos;ll work on a layout test, but it may be challenging since it is dependent on GC running at the right time.

Index: ScriptElement.cpp
===================================================================
--- ScriptElement.cpp   (revision 2802)
+++ ScriptElement.cpp   (working copy)
@@ -180,10 +180,13 @@
     CachedScript* cs = static_cast&lt;CachedScript*&gt;(o);
     ASSERT(cs == m_cachedScript);
+    // Evaluating the script could lead to a garbage collection which can
+    // delete the script element so we need to protect it.
+    RefPtr&lt;Element&gt; protector(m_element);
+
     if (cs-&gt;errorOccurred())
         m_scriptElement-&gt;dispatchErrorEvent();
     else {
-        RefPtr&lt;Element&gt; protector(m_element);
         evaluateScript(cs-&gt;url(), cs-&gt;script());
         m_scriptElement-&gt;dispatchLoadEvent();
     }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93917</commentid>
    <comment_count>3</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-10-03 11:30:28 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; This patch, which essentially just rolls back part of the original change,
&gt; seems to resolve the bug.  I&apos;ll work on a layout test, but it may be
&gt; challenging since it is dependent on GC running at the right time.
&gt; 
&gt; Index: ScriptElement.cpp
&gt; ===================================================================
&gt; --- ScriptElement.cpp   (revision 2802)
&gt; +++ ScriptElement.cpp   (working copy)
&gt; @@ -180,10 +180,13 @@
&gt;      CachedScript* cs = static_cast&lt;CachedScript*&gt;(o);
&gt;      ASSERT(cs == m_cachedScript);
&gt; +    // Evaluating the script could lead to a garbage collection which can
&gt; +    // delete the script element so we need to protect it.
&gt; +    RefPtr&lt;Element&gt; protector(m_element);
&gt; +
&gt;      if (cs-&gt;errorOccurred())
&gt;          m_scriptElement-&gt;dispatchErrorEvent();
&gt;      else {
&gt; -        RefPtr&lt;Element&gt; protector(m_element);
&gt;          evaluateScript(cs-&gt;url(), cs-&gt;script());
&gt;          m_scriptElement-&gt;dispatchLoadEvent();
&gt;      }
&gt; 

The change looks good.  We just need a changelog, and ideally a layout test.

gc() or GCController.collect() should be able to kick off GC when you need.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94020</commentid>
    <comment_count>4</comment_count>
      <attachid>24076</attachid>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-10-03 17:14:38 -0700</bug_when>
    <thetext>Created attachment 24076
v1 patch

Here&apos;s the patch sans layout test.  Try as I might, I could not get my Mac build of WebKit to crash upon reaching ScriptElementData::stopLoadRequest despite having a junk |this| pointer.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94023</commentid>
    <comment_count>5</comment_count>
      <attachid>24077</attachid>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-10-03 18:08:53 -0700</bug_when>
    <thetext>Created attachment 24077
v2 patch - same as before, but includes bug title in ChangeLog

I tried using GuardMalloc to help create a test, but it seems like there is something else besides this issue that is causing DRT to crash under GuardMalloc.  For example, fast/dom/script-element-gc.html crashes with or without my fix under GuardMalloc.  I don&apos;t know how to get a call stack when GuardMalloc detects an error, so I don&apos;t know why DRT is crashing under GuardMalloc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94076</commentid>
    <comment_count>6</comment_count>
      <attachid>24077</attachid>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-10-04 02:59:40 -0700</bug_when>
    <thetext>Comment on attachment 24077
v2 patch - same as before, but includes bug title in ChangeLog

Looks great.  Thanks for fixing this.  It would be better w/ a layout test, but from discussions in the channel it sounds like you were having trouble getting one to work on your Mac.

I think you have commit-bit these days, so you should be able to land this yourself.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94077</commentid>
    <comment_count>7</comment_count>
    <who name="Eric Seidel (no email)">eric</who>
    <bug_when>2008-10-04 03:00:37 -0700</bug_when>
    <thetext>(In reply to comment #5)
&gt; Created an attachment (id=24077) [edit]
&gt; v2 patch - same as before, but includes bug title in ChangeLog
&gt; 
&gt; I tried using GuardMalloc to help create a test, but it seems like there is
&gt; something else besides this issue that is causing DRT to crash under
&gt; GuardMalloc.  For example, fast/dom/script-element-gc.html crashes with or
&gt; without my fix under GuardMalloc.  I don&apos;t know how to get a call stack when
&gt; GuardMalloc detects an error, so I don&apos;t know why DRT is crashing under
&gt; GuardMalloc.
&gt; 

We need to file any --guard crashes for run-webkit-tests as bugs.   Or rather, when you see any, don&apos;t hesitate to file them.  We really should have a buildbot which runs run-webkit-tests --guard once a week or something.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94142</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Fisher (:fishd, Google)">fishd</who>
    <bug_when>2008-10-04 23:51:05 -0700</bug_when>
    <thetext>I filed bug 21380 about how &quot;run-webkit-tests -g&quot; just crashes for me on seemingly every test.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>94223</commentid>
    <comment_count>9</comment_count>
    <who name="Nikolas Zimmermann">zimmermann</who>
    <bug_when>2008-10-06 06:08:01 -0700</bug_when>
    <thetext>Oops, good catch! My fault while refactoring the code... Sorry for any headaches.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>24076</attachid>
            <date>2008-10-03 17:14:38 -0700</date>
            <delta_ts>2008-10-03 18:08:53 -0700</delta_ts>
            <desc>v1 patch</desc>
            <filename>script-element-1.diff</filename>
            <type>text/plain</type>
            <size>1461</size>
            <attacher name="Darin Fisher (:fishd, Google)">fishd</attacher>
            
              <data encoding="base64">SW5kZXg6IENoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBDaGFuZ2VMb2cJKHJldmlzaW9uIDM3MjY3
KQorKysgQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTYgQEAKKzIwMDgtMTAt
MDMgIERhcmluIEZpc2hlciAgPGRhcmluQGNocm9taXVtLm9yZz4KKworICAgICAgICBSZXZpZXdl
ZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBXQVJOSU5HOiBOTyBURVNUIENBU0VTIEFE
REVEIE9SIENIQU5HRUQKKworICAgICAgICBGaXhlcyBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9z
aG93X2J1Zy5jZ2k/aWQ9MjEzMjkKKworICAgICAgICAqIGRvbS9TY3JpcHRFbGVtZW50LmNwcDoK
KyAgICAgICAgKFd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50KTsKKwogICAgIGlmIChjcy0+ZXJyb3JPY2N1cnJlZCgpKQogICAg
ICAgICBtX3NjcmlwdEVsZW1lbnQtPmRpc3BhdGNoRXJyb3JFdmVudCgpOwogICAgIGVsc2Ugewot
ICAgICAgICBSZWZQdHI8RWxlbWVudD4gcHJvdGVjdG9yKG1fZWxlbWVudCk7CiAgICAgICAgIGV2
YWx1YXRlU2NyaXB0KGNzLT51cmwoKSwgY3MtPnNjcmlwdCgpKTsKICAgICAgICAgbV9zY3JpcHRF
bGVtZW50LT5kaXNwYXRjaExvYWRFdmVudCgpOwogICAgIH0K
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>24077</attachid>
            <date>2008-10-03 18:08:53 -0700</date>
            <delta_ts>2008-10-04 02:59:40 -0700</delta_ts>
            <desc>v2 patch - same as before, but includes bug title in ChangeLog</desc>
            <filename>script-element-2.diff</filename>
            <type>text/plain</type>
            <size>1519</size>
            <attacher name="Darin Fisher (:fishd, Google)">fishd</attacher>
            
              <data encoding="base64">SW5kZXg6IENoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBDaGFuZ2VMb2cJKHJldmlzaW9uIDM3MjY3
KQorKysgQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMTYgQEAKKzIwMDgtMTAt
MDMgIERhcmluIEZpc2hlciAgPGRhcmluQGNocm9taXVtLm9yZz4KKworICAgICAgICBSZXZpZXdl
ZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBXQVJOSU5HOiBOTyBURVNUIENBU0VTIEFE
REVEIE9SIENIQU5HRUQKKworICAgICAgICBSRUdSRVNTSU9OOiBjcmFzaCBpbiBTY3JpcHRFbGVt
ZW50Ojpub3RpZnlGaW5pc2hlZAorICAgICAgICBGaXhlcyBodHRwczovL2J1Z3Mud2Via2l0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QgdG8gcHJvdGVjdCBpdCBhbmQgdXMgd2l0aCBpdCEKKyAgICBSZWZQdHI8RWxlbWVudD4g
cHJvdGVjdG9yKG1fZWxlbWVudCk7CisKICAgICBpZiAoY3MtPmVycm9yT2NjdXJyZWQoKSkKICAg
ICAgICAgbV9zY3JpcHRFbGVtZW50LT5kaXNwYXRjaEVycm9yRXZlbnQoKTsKICAgICBlbHNlIHsK
LSAgICAgICAgUmVmUHRyPEVsZW1lbnQ+IHByb3RlY3RvcihtX2VsZW1lbnQpOwogICAgICAgICBl
dmFsdWF0ZVNjcmlwdChjcy0+dXJsKCksIGNzLT5zY3JpcHQoKSk7CiAgICAgICAgIG1fc2NyaXB0
RWxlbWVudC0+ZGlzcGF0Y2hMb2FkRXZlbnQoKTsKICAgICB9Cg==
</data>
<flag name="review"
          id="10912"
          type_id="1"
          status="+"
          setter="eric"
    />
          </attachment>
      

    </bug>

</bugzilla>