Fix for bug 693364 (Leak in CompartmentPrivate::RegisterDOMExpandoObject). r=Ms2ger.
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 13 Oct 2011 14:40:20 +0200
changeset 78695 fd296c912d2408c364682230bf0a9fad920a83c3
parent 78694 a375341a2a0756464a466e60425324fe6e9484c6
child 78696 10089dd4bd854974a03a7f45aed9b902b2255a4f
push id21326
push userbmo@edmorley.co.uk
push dateFri, 14 Oct 2011 10:00:06 +0000
treeherdermozilla-central@ca73f057dab7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs693364
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 693364 (Leak in CompartmentPrivate::RegisterDOMExpandoObject). r=Ms2ger.
js/src/xpconnect/src/xpcjsruntime.cpp
js/src/xpconnect/src/xpcprivate.h
--- a/js/src/xpconnect/src/xpcjsruntime.cpp
+++ b/js/src/xpconnect/src/xpcjsruntime.cpp
@@ -255,19 +255,16 @@ ContextCallback(JSContext *cx, uintN ope
             delete XPCContext::GetXPCContext(cx);
         }
     }
     return JS_TRUE;
 }
 
 xpc::CompartmentPrivate::~CompartmentPrivate()
 {
-    delete waiverWrapperMap;
-    delete expandoMap;
-    delete domExpandoMap;
     MOZ_COUNT_DTOR(xpc::CompartmentPrivate);
 }
 
 static JSBool
 CompartmentCallback(JSContext *cx, JSCompartment *compartment, uintN op)
 {
     JS_ASSERT(op == JSCOMPARTMENT_DESTROY);
 
--- a/js/src/xpconnect/src/xpcprivate.h
+++ b/js/src/xpconnect/src/xpcprivate.h
@@ -4434,54 +4434,50 @@ XPC_GetIdentityObject(JSContext *cx, JSO
 namespace xpc {
 
 struct CompartmentPrivate
 {
     CompartmentPrivate(PtrAndPrincipalHashKey *key, bool wantXrays, bool cycleCollectionEnabled)
         : key(key),
           ptr(nsnull),
           wantXrays(wantXrays),
-          cycleCollectionEnabled(cycleCollectionEnabled),
-          waiverWrapperMap(nsnull),
-          expandoMap(nsnull),
-          domExpandoMap(nsnull)
+          cycleCollectionEnabled(cycleCollectionEnabled)
     {
         MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
     }
 
     CompartmentPrivate(nsISupports *ptr, bool wantXrays, bool cycleCollectionEnabled)
         : key(nsnull),
           ptr(ptr),
           wantXrays(wantXrays),
-          cycleCollectionEnabled(cycleCollectionEnabled),
-          waiverWrapperMap(nsnull),
-          expandoMap(nsnull),
-          domExpandoMap(nsnull)
+          cycleCollectionEnabled(cycleCollectionEnabled)
     {
         MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
     }
 
     ~CompartmentPrivate();
 
     // NB: key and ptr are mutually exclusive.
     nsAutoPtr<PtrAndPrincipalHashKey> key;
     nsCOMPtr<nsISupports> ptr;
     bool wantXrays;
     bool cycleCollectionEnabled;
-    JSObject2JSObjectMap *waiverWrapperMap;
+    nsAutoPtr<JSObject2JSObjectMap> waiverWrapperMap;
     // NB: we don't want this map to hold a strong reference to the wrapper.
-    nsDataHashtable<nsPtrHashKey<XPCWrappedNative>, JSObject *> *expandoMap;
-    nsTHashtable<nsPtrHashKey<JSObject> > *domExpandoMap;
+    nsAutoPtr<nsDataHashtable<nsPtrHashKey<XPCWrappedNative>, JSObject *> > expandoMap;
+    nsAutoPtr<nsTHashtable<nsPtrHashKey<JSObject> > > domExpandoMap;
     nsCString location;
 
     bool RegisterExpandoObject(XPCWrappedNative *wn, JSObject *expando) {
         if (!expandoMap) {
             expandoMap = new nsDataHashtable<nsPtrHashKey<XPCWrappedNative>, JSObject *>();
-            if (!expandoMap->Init(8))
+            if (!expandoMap->Init(8)) {
+                expandoMap = nsnull;
                 return false;
+            }
         }
         return expandoMap->Put(wn, expando);
     }
 
     /**
      * This lookup does not change the color of the JSObject meaning that the
      * object returned is not guaranteed to be kept alive past the next CC.
      *
@@ -4501,18 +4497,17 @@ struct CompartmentPrivate
         JSObject *obj = LookupExpandoObjectPreserveColor(wn);
         xpc_UnmarkGrayObject(obj);
         return obj;
     }
 
     bool RegisterDOMExpandoObject(JSObject *expando) {
         if (!domExpandoMap) {
             domExpandoMap = new nsTHashtable<nsPtrHashKey<JSObject> >();
-            if(!domExpandoMap->Init(8))
-            {
+            if(!domExpandoMap->Init(8)) {
                 domExpandoMap = nsnull;
                 return false;
             }
         }
         return domExpandoMap->PutEntry(expando);
     }
     void RemoveDOMExpandoObject(JSObject *expando) {
         if(domExpandoMap)