Bug 1311687 - Pop eval context on early returns. r=peterv
☠☠ backed out by a3c15e0b3c4c ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Mon, 07 Nov 2016 10:31:50 -0800
changeset 324742 667c1a30679730fbf513e310b2768bc8eea5cc51
parent 324741 f2631b49bb7d178dde8e5f2f4b740803453fbbb4
child 324743 32f776e0c7b56e905d929efa1aa13e46849b6223
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerspeterv
bugs1311687
milestone53.0a1
Bug 1311687 - Pop eval context on early returns. r=peterv Make sure the eval context stack is cleaned up on failure. MozReview-Commit-ID: AUNen1xt9He
dom/xslt/xslt/txExecutionState.cpp
--- a/dom/xslt/xslt/txExecutionState.cpp
+++ b/dom/xslt/xslt/txExecutionState.cpp
@@ -222,43 +222,57 @@ txExecutionState::getVariable(int32_t aN
     // evaluate the global variable
     pushEvalContext(mInitialEvalContext);
     if (var->mExpr) {
         txVariableMap* oldVars = mLocalVariables;
         mLocalVariables = nullptr;
         rv = var->mExpr->evaluate(getEvalContext(), &aResult);
         mLocalVariables = oldVars;
 
-        NS_ENSURE_SUCCESS(rv, rv);
+        if (NS_FAILED(rv)) {
+          popEvalContext();
+          return rv;
+        }
     }
     else {
         nsAutoPtr<txRtfHandler> rtfHandler(new txRtfHandler);
-        NS_ENSURE_TRUE(rtfHandler, NS_ERROR_OUT_OF_MEMORY);
 
         rv = pushResultHandler(rtfHandler);
-        NS_ENSURE_SUCCESS(rv, rv);
-        
+        if (NS_FAILED(rv)) {
+          popEvalContext();
+          return rv;
+        }
+
         rtfHandler.forget();
 
         txInstruction* prevInstr = mNextInstruction;
         // set return to nullptr to stop execution
         mNextInstruction = nullptr;
         rv = runTemplate(var->mFirstInstruction);
-        NS_ENSURE_SUCCESS(rv, rv);
+        if (NS_FAILED(rv)) {
+          popEvalContext();
+          return rv;
+        }
 
         pushTemplateRule(nullptr, txExpandedName(), nullptr);
         rv = txXSLTProcessor::execute(*this);
-        NS_ENSURE_SUCCESS(rv, rv);
+        if (NS_FAILED(rv)) {
+          popEvalContext();
+          return rv;
+        }
 
         popTemplateRule();
 
         mNextInstruction = prevInstr;
         rtfHandler = (txRtfHandler*)popResultHandler();
         rv = rtfHandler->getAsRTF(&aResult);
-        NS_ENSURE_SUCCESS(rv, rv);
+        if (NS_FAILED(rv)) {
+          popEvalContext();
+          return rv;
+        }
     }
     popEvalContext();
 
     // Remove the placeholder and insert the calculated value
     mGlobalVariableValues.removeVariable(name);
     rv = mGlobalVariableValues.bindVariable(name, aResult);
     if (NS_FAILED(rv)) {
         NS_RELEASE(aResult);