Bug 785060 - Check for allocation failure in JS_NewUCStringCopyZ calls; r=Ms2ger

This commit is contained in:
Nagarjuna Varma 2012-12-22 18:35:07 -05:00
parent b62b852e17
commit ec1be4c9ac
3 changed files with 7 additions and 0 deletions

View File

@ -1492,6 +1492,11 @@ nsHTMLMediaElement::BuildObjectFromTags(nsCStringHashKey::KeyType aKey,
nsString wideValue = NS_ConvertUTF8toUTF16(aValue);
JSString* string = JS_NewUCStringCopyZ(args->cx, wideValue.Data());
if (!string) {
NS_WARNING("Failed to perform string copy");
args->error = true;
return PL_DHASH_STOP;
}
JS::Value value = STRING_TO_JSVAL(string);
if (!JS_DefineProperty(args->cx, args->tags, aKey.Data(), value,
NULL, NULL, JSPROP_ENUMERATE)) {

View File

@ -631,6 +631,7 @@ bool SetStringProperty(JSContext *cx, JSObject *aObject, const char *aProperty,
return true;
}
JSString* strValue = JS_NewUCStringCopyZ(cx, aValue.get());
NS_ENSURE_TRUE(strValue, false);
jsval valValue = STRING_TO_JSVAL(strValue);
return JS_SetProperty(cx, aObject, aProperty, &valValue);
}

View File

@ -168,6 +168,7 @@ nsHTTPIndex::OnFTPControlLog(bool server, const char *msg)
unicodeMsg.AssignWithConversion(msg);
JSAutoRequest ar(cx);
JSString* jsMsgStr = JS_NewUCStringCopyZ(cx, (jschar*) unicodeMsg.get());
NS_ENSURE_TRUE(jsMsgStr, NS_ERROR_OUT_OF_MEMORY);
params[0] = BOOLEAN_TO_JSVAL(server);
params[1] = STRING_TO_JSVAL(jsMsgStr);