Bug 914017 - Initialize members variables of the document hash correctly. r=sicking, a=abillings
authorPeter Van der Beken <peterv@propagandism.org>
Thu, 26 Sep 2013 12:58:25 +0200
changeset 120053 05db0f8744fa08f9f25372aa44ac6bf7be71e349
parent 120052 2d1fe68319ccfcf27018a0e134c6af0eb6ae24c4
child 120054 bb1ba0f59b3143d8b8b5b9279d08a1867d8c8849
push id99
push userryanvm@gmail.com
push dateFri, 18 Oct 2013 00:45:52 +0000
reviewerssicking, abillings
bugs914017
milestone18.1
Bug 914017 - Initialize members variables of the document hash correctly. r=sicking, a=abillings
content/xslt/src/xslt/txExecutionState.cpp
content/xslt/src/xslt/txExecutionState.h
--- a/content/xslt/src/xslt/txExecutionState.cpp
+++ b/content/xslt/src/xslt/txExecutionState.cpp
@@ -11,47 +11,43 @@
 #include "txRtfHandler.h"
 #include "txXSLTProcessor.h"
 #include "txLog.h"
 #include "txURIUtils.h"
 #include "txXMLParser.h"
 
 const int32_t txExecutionState::kMaxRecursionDepth = 20000;
 
-nsresult txLoadedDocumentsHash::init(txXPathNode* aSourceDocument)
+void
+txLoadedDocumentsHash::init(txXPathNode* aSourceDocument)
 {
     Init(8);
 
     mSourceDocument = aSourceDocument;
     
     nsAutoString baseURI;
     txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
 
-    txLoadedDocumentEntry* entry = PutEntry(baseURI);
-    if (!entry) {
-        return NS_ERROR_FAILURE;
-    }
-
-    entry->mDocument = mSourceDocument;
-
-    return NS_OK;
+    PutEntry(baseURI)->mDocument = mSourceDocument;
 }
 
 txLoadedDocumentsHash::~txLoadedDocumentsHash()
 {
     if (!IsInitialized()) {
         return;
     }
 
-    nsAutoString baseURI;
-    txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
+    if (mSourceDocument) {
+        nsAutoString baseURI;
+        txXPathNodeUtils::getBaseURI(*mSourceDocument, baseURI);
 
-    txLoadedDocumentEntry* entry = GetEntry(baseURI);
-    if (entry) {
-        delete entry->mDocument.forget();
+        txLoadedDocumentEntry* entry = GetEntry(baseURI);
+        if (entry) {
+            delete entry->mDocument.forget();
+        }
     }
 }
 
 txExecutionState::txExecutionState(txStylesheet* aStylesheet,
                                    bool aDisableLoads)
     : mOutputHandler(nullptr),
       mResultHandler(nullptr),
       mStylesheet(aStylesheet),
@@ -119,24 +115,17 @@ txExecutionState::init(const txXPathNode
         createHandlerWith(mStylesheet->getOutputFormat(), &handler);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mOutputHandler = handler;
     mResultHandler = handler;
     mOutputHandler->startDocument();
 
     // Set up loaded-documents-hash
-    nsAutoPtr<txXPathNode> document(txXPathNodeUtils::getOwnerDocument(aNode));
-    NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
-
-    rv = mLoadedDocuments.init(document);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // loaded-documents-hash owns this now
-    document.forget();
+    mLoadedDocuments.init(txXPathNodeUtils::getOwnerDocument(aNode));
 
     // Init members
     rv = mKeyHash.init();
     NS_ENSURE_SUCCESS(rv, rv);
     
     mRecycler = new txResultRecycler;
     NS_ENSURE_TRUE(mRecycler, NS_ERROR_OUT_OF_MEMORY);
     
--- a/content/xslt/src/xslt/txExecutionState.h
+++ b/content/xslt/src/xslt/txExecutionState.h
@@ -51,18 +51,22 @@ public:
 
     nsAutoPtr<txXPathNode> mDocument;
     nsresult mLoadResult;
 };
 
 class txLoadedDocumentsHash : public nsTHashtable<txLoadedDocumentEntry>
 {
 public:
+     txLoadedDocumentsHash()
+        : mSourceDocument(nullptr)
+     {
+     }
     ~txLoadedDocumentsHash();
-    nsresult init(txXPathNode* aSourceDocument);
+    void init(txXPathNode* aSourceDocument);
 
 private:
     friend class txExecutionState;
     txXPathNode* mSourceDocument;
 };
 
 
 class txExecutionState : public txIMatchContext