<?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>16920</bug_id>
          
          <creation_ts>2008-01-17 22:36:47 -0800</creation_ts>
          <short_desc>Crash inside garbage collector with simple code</short_desc>
          <delta_ts>2012-03-11 14:55:31 -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>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows Vista</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</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="Cameron McCormack (:heycam)">heycam</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>barraclough</cc>
    
    <cc>mrowe</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>67572</commentid>
    <comment_count>0</comment_count>
    <who name="Cameron McCormack (:heycam)">heycam</who>
    <bug_when>2008-01-17 22:36:47 -0800</bug_when>
    <thetext>With some simple use of the JSCore API, I get a crash when calling JSGarbageCollect().

Reduced test case by bdash:

// Put me in test.c
// gcc -o test test.c -framework JavaScriptCore
// Run me against a debug build of JavaScriptCore like so:
// DYLD_FRAMEWORK_PATH=WebKitBuild/Debug DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib ./test

#include &lt;JavaScriptCore/JavaScriptCore.h&gt;
#include &lt;stdio.h&gt;

void doIt()
{
  JSClassDefinition definition = kJSClassDefinitionEmpty;
  JSClassRef a, b;
  JSGlobalContextRef global;
  definition.className = &quot;A&quot;;
  a = JSClassCreate(&amp;definition);

  definition = kJSClassDefinitionEmpty;
  definition.className = &quot;B&quot;;
  definition.parentClass = a;
  b = JSClassCreate(&amp;definition);

  global = JSGlobalContextCreate(b);
  JSGlobalContextRelease(global);
  JSClassRelease(b);
  JSClassRelease(a);
  JSGarbageCollect(NULL);
  printf(&quot;Done\n&quot;);
}


int main(int argc, char **argv)
{
  int i;
  for (i = 0; i &lt; 1000; i++)
    doIt();
  return 0;
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67573</commentid>
    <comment_count>1</comment_count>
    <who name="Cameron McCormack (:heycam)">heycam</who>
    <bug_when>2008-01-17 22:38:03 -0800</bug_when>
    <thetext>Backtrack from bdash:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000b0812fd0
Crashed Thread:  0

Thread 0 Crashed:
0   com.apple.JavaScriptCore              0x002d7df3 KJS::JSCallbackObject&lt;KJS::JSGlobalObject&gt;::~JSCallbackObject() + 57 (JSCallbackObjectFunctions.h:86)
1   com.apple.JavaScriptCore              0x002d7e63 KJS::JSCallbackObject&lt;KJS::JSGlobalObject&gt;::~JSCallbackObject() + 17 (JSCallbackObjectFunctions.h:90)
2   com.apple.JavaScriptCore              0x002a6f70 unsigned long KJS::Collector::sweep&lt;(KJS::Collector::HeapType)0&gt;(bool) + 760 (collector.cpp:883)
3   com.apple.JavaScriptCore              0x00277dee KJS::Collector::collect() + 382 (collector.cpp:963)
4   com.apple.JavaScriptCore              0x002d17b8 JSGarbageCollect + 34 (JSBase.cpp:83)
5   test                                  0x00001fba doIt + 192
6   test                                  0x00001fe2 main + 20
7   test                                  0x00001ece start + 54

And one from me, on Windows:

&gt;        myapp.exe!KJS::JSCallbackObject&lt;KJS::JSGlobalObject&gt;::~JSCallbackObject&lt;KJS::JSGlobalObject&gt;()  Line 105 + 0x7 bytes        C++
         myapp.exe!KJS::JSCallbackObject&lt;KJS::JSGlobalObject&gt;::`scalar deleting destructor&apos;()  + 0xf bytes        C++
         myapp.exe!KJS::Collector::sweep&lt;0&gt;(bool currentThreadIsMainThread=false)  Line 883        C++
         myapp.exe!KJS::Collector::collect()  Line 963 + 0x9 bytes        C++
         myapp.exe!JSGarbageCollect(const OpaqueJSContext * __formal=0x00000000)  Line 87        C++
         myapp.exe!myfunction(void * pUserData=0x020d734c, void * pDocument=0x020cfdf8, void * * ppDocumentUserData=0x020d16e4)  Line 271 + 0x7 bytes        C
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>67574</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2008-01-17 22:43:03 -0800</bug_when>
    <thetext>&lt;rdar://problem/5694270&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>68765</commentid>
    <comment_count>3</comment_count>
    <who name="Cameron McCormack (:heycam)">heycam</who>
    <bug_when>2008-01-29 22:40:29 -0800</bug_when>
    <thetext>A workaround is to do an additional JSGarbageCollect() just before the JSGlobalContextRelease() call.

I wonder whether making OpaqueJSClass retain its parentClass would solve the problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>575833</commentid>
    <comment_count>4</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2012-03-11 14:55:31 -0700</bug_when>
    <thetext>Works for me in ToT, looks like this has been fixed.  Please reopen if you can still repro the problem.

cheers, G.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>