Bug 635298 - Check return value of JS_ValueToString() (r=luke, a=gal)
authorSteve Fink <sfink@mozilla.com>
Fri, 18 Feb 2011 14:27:00 -0800
changeset 62972 a8926981d45261fcf234feb51f30f580bb644c51
parent 62971 711804514c8ef7e9065925a8080fbb60f84ba813
child 62973 0907c4ca12471120b0cc1780d330123332a76af0
child 63083 0c398bad4c9935f55fd29087b0f09630ecd5fae1
push idunknown
push userunknown
push dateunknown
reviewersluke, gal
bugs635298
milestone2.0b12pre
Bug 635298 - Check return value of JS_ValueToString() (r=luke, a=gal)
js/jsd/jsd_val.c
--- a/js/jsd/jsd_val.c
+++ b/js/jsd/jsd_val.c
@@ -236,19 +236,23 @@ jsd_GetValueString(JSDContext* jsdc, JSD
     }
     exceptionState = JS_SaveExceptionState(cx);
 
     string = JS_ValueToString(cx, jsdval->val);
 
     JS_RestoreExceptionState(cx, exceptionState);
     JS_LeaveCrossCompartmentCall(call);
 
-    stringval = STRING_TO_JSVAL(string);
-    call = JS_EnterCrossCompartmentCall(cx, jsdc->glob);
-    if(!call || !JS_WrapValue(cx, &stringval)) {
+    if(string) {
+        stringval = STRING_TO_JSVAL(string);
+        call = JS_EnterCrossCompartmentCall(cx, jsdc->glob);
+    }
+    if(!string || !call || !JS_WrapValue(cx, &stringval)) {
+        if(call)
+            JS_LeaveCrossCompartmentCall(call);
         JS_EndRequest(cx);
         return NULL;
     }
 
     jsdval->string = JSVAL_TO_STRING(stringval);
     if(!JS_AddNamedStringRoot(cx, &jsdval->string, "ValueString"))
         jsdval->string = NULL;