Ignore:
Timestamp:
Aug 18, 2008, 1:09:59 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Maciej.

Make JSGlobalContextRetain/Release actually work.

  • API/JSContextRef.cpp: (JSGlobalContextRetain): (JSGlobalContextRelease): Ref/deref global data to give checking for globalData.refCount() some sense.
  • API/tests/testapi.c: (main): Added a test for this bug.
  • kjs/JSGlobalData.cpp: (KJS::JSGlobalData::~JSGlobalData): While checking for memory leaks, found that JSGlobalData::emptyList has changed to a pointer, but it was not destructed, causing a huge leak in run-webkit-tests --threaded.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSContextRef.cpp

    r35663 r35815  
    8282{
    8383    ExecState* exec = toJS(ctx);
    84     exec->globalData().heap->registerThread();
     84    JSGlobalData& globalData = exec->globalData();
     85
     86    globalData.heap->registerThread();
    8587
    8688    gcProtect(exec->dynamicGlobalObject());
     89    globalData.ref();
    8790    return ctx;
    8891}
     
    9598
    9699    JSGlobalData& globalData = exec->globalData();
    97     if (globalData.refCount() == 1) {
     100    if (globalData.refCount() == 2) { // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain().
    98101        // The last reference was released, this is our last chance to collect.
    99102        Heap* heap = globalData.heap;
     
    102105        ASSERT(!heap->isBusy());
    103106
    104         // Heap destructor will delete JSGlobalObject, which will in turn delete JSGlobalData, which will
    105         // delete the heap, which would cause a crash if allowed.
     107        delete heap;
    106108        globalData.heap = 0;
     109    }
    107110
    108         delete heap;
    109     }
     111    globalData.deref();
    110112}
    111113
Note: See TracChangeset for help on using the changeset viewer.