Bug 1332233 - prevent resource leak in CustomElementRegistry::Define. r?baku draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Thu, 19 Jan 2017 14:31:33 +0200
changeset 463591 eec4bb5783c3e4eb613453de995eadfac2c8a22d
parent 463342 96cb95af530477edb66ae48d98c18533476e57bb
child 542730 7a9ccccc4c58281cf1fff24bfdcd5141df4794a7
push id42124
push userbmo:bpostelnicu@mozilla.com
push dateThu, 19 Jan 2017 12:33:32 +0000
reviewersbaku
bugs1332233
milestone53.0a1
Bug 1332233 - prevent resource leak in CustomElementRegistry::Define. r?baku MozReview-Commit-ID: AzXgls3lKCA
dom/base/CustomElementRegistry.cpp
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -767,32 +767,33 @@ CustomElementRegistry::Define(const nsAS
    * 11. Let definition be a new custom element definition with name name,
    *     local name localName, constructor constructor, prototype prototype,
    *     observed attributes observedAttributes, and lifecycle callbacks
    *     lifecycleCallbacks.
    */
   // Associate the definition with the custom element.
   nsCOMPtr<nsIAtom> localNameAtom(NS_Atomize(localName));
   LifecycleCallbacks* callbacks = callbacksHolder.forget();
-  CustomElementDefinition* definition =
-    new CustomElementDefinition(nameAtom,
-                                localNameAtom,
-                                constructor,
-                                constructorPrototype,
-                                callbacks,
-                                0 /* TODO dependent on HTML imports. Bug 877072 */);
 
   /**
    * 12. Add definition to this CustomElementRegistry.
    */
   if (!mConstructors.put(constructorUnwrapped, nameAtom)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
+  CustomElementDefinition* definition =
+    new CustomElementDefinition(nameAtom,
+                                localNameAtom,
+                                constructor,
+                                constructorPrototype,
+                                callbacks,
+                                0 /* TODO dependent on HTML imports. Bug 877072 */);
+
   mCustomDefinitions.Put(nameAtom, definition);
 
   MOZ_ASSERT(mCustomDefinitions.Count() == mConstructors.count(),
              "Number of entries should be the same");
 
   /**
    * 13. 14. 15. Upgrade candidates
    */