From e8afb19765f76ca177fea191ae5be06bee4a7757 Mon Sep 17 00:00:00 2001 From: Pale Moon Date: Tue, 21 Nov 2017 15:27:42 +0100 Subject: In order to not leak properties, ensure all the properties of adopted nodes are removed in case the adopt call fails. --- dom/base/nsNodeUtils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'dom/base/nsNodeUtils.cpp') diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp index 8806773a4..517700907 100644 --- a/dom/base/nsNodeUtils.cpp +++ b/dom/base/nsNodeUtils.cpp @@ -498,6 +498,15 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep, } } + if (aNode->HasProperties()) { + bool ok = aNodesWithProperties.AppendObject(aNode); + MOZ_RELEASE_ASSERT(ok, "Out of memory"); + if (aClone) { + ok = aNodesWithProperties.AppendObject(clone); + MOZ_RELEASE_ASSERT(ok, "Out of memory"); + } + } + // Cloning template element. if (aDeep && aClone && IsTemplateElement(aNode)) { DocumentFragment* origContent = @@ -541,15 +550,6 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep, } #endif - if (aNode->HasProperties()) { - bool ok = aNodesWithProperties.AppendObject(aNode); - if (aClone) { - ok = ok && aNodesWithProperties.AppendObject(clone); - } - - NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY); - } - clone.forget(aResult); return NS_OK; -- cgit v1.2.3