Bug 634752 - Always drop jsPrincipals before returning from LoadSubScript, r+a=jst
authorMichael Wu <mwu@mozilla.com>
Thu, 17 Feb 2011 14:20:00 -0800
changeset 62769 155f765cad6f2599de38e33478b8eb4b071af09e
parent 62768 cd63bb369f1c429b0e83a8ed35c2c68acc6d5e74
child 62770 03016b7831d85ede12b44595828b49ed8b9043bb
push idunknown
push userunknown
push dateunknown
bugs634752
milestone2.0b12pre
Bug 634752 - Always drop jsPrincipals before returning from LoadSubScript, r+a=jst
js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
--- a/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/src/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -387,43 +387,44 @@ mozJSSubScriptLoader::LoadSubScript (con
     {
         nsString script;
         rv = nsScriptLoader::ConvertToUTF16(
                 nsnull, reinterpret_cast<PRUint8*>(buf.get()), len,
                 nsDependentString(reinterpret_cast<PRUnichar*>(charset)), nsnull, script);
 
         if (NS_FAILED(rv))
         {
+            JSPRINCIPALS_DROP(cx, jsPrincipals);
             errmsg = JS_NewStringCopyZ(cx, LOAD_ERROR_BADCHARSET);
             goto return_exception;
         }
         ok = JS_EvaluateUCScriptForPrincipals(cx, target_obj, jsPrincipals,
                                               reinterpret_cast<const jschar*>(script.get()),
                                               script.Length(), uriStr.get(), 1, rval);
     }
     else
     {
         ok = JS_EvaluateScriptForPrincipals(cx, target_obj, jsPrincipals,
                                             buf, len, uriStr.get(), 1, rval);
     }
 
+    JSPRINCIPALS_DROP(cx, jsPrincipals);
+
     if (ok)
     {
         JSAutoEnterCompartment rac;
 
         if (!rac.enter(cx, result_obj) || !JS_WrapValue(cx, rval))
             return NS_ERROR_UNEXPECTED; 
     }
 
     /* repent for our evil deeds */
     JS_SetErrorReporter (cx, er);
 
     cc->SetReturnValueWasSet (ok);
-
-    JSPRINCIPALS_DROP(cx, jsPrincipals);
     return NS_OK;
 
  return_exception:
     JS_SetPendingException (cx, STRING_TO_JSVAL(errmsg));
     return NS_OK;
 }
 
 #endif /* NO_SUBSCRIPT_LOADER */