<?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>107978</bug_id>
          
          <creation_ts>2013-01-25 12:49:17 -0800</creation_ts>
          <short_desc>Objective-C API: JSContext&apos;s dealloc causes ASSERT due to ordering of releases</short_desc>
          <delta_ts>2013-01-30 21:08:34 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Mark Hahnenberg">mhahnenberg</reporter>
          <assigned_to name="Mark Hahnenberg">mhahnenberg</assigned_to>
          <cc>barraclough</cc>
    
    <cc>ggaren</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>816851</commentid>
    <comment_count>0</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-01-25 12:49:17 -0800</bug_when>
    <thetext>JSGlobalContextRelease should be the last release of a JSContextGroupRef to make sure that Identifier table is that of the current virtual machine when that virtual machine is destroyed. In the current order, we save the Identifier table from the last JSGlobalData, load our table, deref the JSGlobalData (which is not destroyed because there&apos;s still a reference from the JSVirtualMachine object), then we restore the old Identifier table. When the JSVirtualMachine calls JSContextGroupRelease, the JSGlobalData will be destroyed with the incorrect Identifier table loaded in wtfThreadData().

We can either reorder these calls in JSContext&apos;s dealloc or make it so that JSContextGroupRelease also does the save/restore of the Identifier table like JSGlobalContextRelease.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>819364</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-01-29 14:56:06 -0800</bug_when>
    <thetext>This is a bug in C API. We need to add the Identifier table save/restore in JSContextGroupRelease.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>820557</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2013-01-30 14:22:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/13118874&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>820589</commentid>
    <comment_count>3</comment_count>
      <attachid>185578</attachid>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-01-30 14:35:37 -0800</bug_when>
    <thetext>Created attachment 185578
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>820621</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-01-30 14:48:24 -0800</bug_when>
    <thetext>Committed r141321: &lt;http://trac.webkit.org/changeset/141321&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>820668</commentid>
    <comment_count>5</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2013-01-30 15:16:17 -0800</bug_when>
    <thetext>+        JSLockHolder lock(globalData);

I don&apos;t think this is valid -- you&apos;ll end up unlocking the lock after you&apos;ve deallocated the JSGlobalData. I think you can just eliminate the lock and rely on thread-safe refcounting.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>820966</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2013-01-30 18:59:05 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; +        JSLockHolder lock(globalData);
&gt; 
&gt; I don&apos;t think this is valid -- you&apos;ll end up unlocking the lock after you&apos;ve deallocated the JSGlobalData. I think you can just eliminate the lock and rely on thread-safe refcounting.

JSLockHolder refs the JSGlobalData when it locks it, so it will only be destroyed after the lock has released the JSGlobalData. I think you&apos;re right that we don&apos;t need the lock though. I was just trying to replicate what JSGlobalContextRelease does.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>821050</commentid>
    <comment_count>7</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2013-01-30 21:08:34 -0800</bug_when>
    <thetext>&gt; JSLockHolder refs the JSGlobalData when it locks it, so it will only be destroyed after the lock has released the JSGlobalData.

Cool cool.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>185578</attachid>
            <date>2013-01-30 14:35:37 -0800</date>
            <delta_ts>2013-01-30 14:42:39 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-107978-20130130143222.patch</filename>
            <type>text/plain</type>
            <size>1705</size>
            <attacher name="Mark Hahnenberg">mhahnenberg</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTQxMzEyKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE2IEBA
CisyMDEzLTAxLTMwICBNYXJrIEhhaG5lbmJlcmcgIDxtaGFobmVuYmVyZ0BhcHBsZS5jb20+CisK
KyAgICAgICAgT2JqZWN0aXZlLUMgQVBJOiBKU0NvbnRleHQncyBkZWFsbG9jIGNhdXNlcyBBU1NF
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EoKIAogdm9pZCBKU0NvbnRleHRHcm91cFJlbGVhc2UoSlNDb250
ZXh0R3JvdXBSZWYgZ3JvdXApCiB7Ci0gICAgdG9KUyhncm91cCktPmRlcmVmKCk7CisgICAgSWRl
bnRpZmllclRhYmxlKiBzYXZlZElkZW50aWZpZXJUYWJsZTsKKyAgICBKU0dsb2JhbERhdGEmIGds
b2JhbERhdGEgPSAqdG9KUyhncm91cCk7CisKKyAgICB7CisgICAgICAgIEpTTG9ja0hvbGRlciBs
b2NrKGdsb2JhbERhdGEpOworICAgICAgICBzYXZlZElkZW50aWZpZXJUYWJsZSA9IHd0ZlRocmVh
ZERhdGEoKS5zZXRDdXJyZW50SWRlbnRpZmllclRhYmxlKGdsb2JhbERhdGEuaWRlbnRpZmllclRh
YmxlKTsKKyAgICAgICAgZ2xvYmFsRGF0YS5kZXJlZigpOworICAgIH0KKworICAgIHd0ZlRocmVh
ZERhdGEoKS5zZXRDdXJyZW50SWRlbnRpZmllclRhYmxlKHNhdmVkSWRlbnRpZmllclRhYmxlKTsK
IH0KIAogLy8gRnJvbSB0aGUgQVBJJ3MgcGVyc3BlY3RpdmUsIGEgZ2xvYmFsIGNvbnRleHQgcmVt
YWlucyBhbGl2ZSBpZmYgaXQgaGFzIGJlZW4gSlNHbG9iYWxDb250ZXh0UmV0YWluZWQuCg==
</data>
<flag name="review"
          id="204692"
          type_id="1"
          status="+"
          setter="fpizlo"
    />
          </attachment>
      

    </bug>

</bugzilla>