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 79337 fd296c912d2408c364682230bf0a9fad920a83c3
parent 79336 a375341a2a0756464a466e60425324fe6e9484c6
child 79338 10089dd4bd854974a03a7f45aed9b902b2255a4f
push idunknown
push userunknown
push dateunknown
reviewersMs2ger
bugs693364
milestone10.0a1
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)