Bug 785060 - Check for allocation failure in JS_NewUCStringCopyZ calls; r=Ms2ger
authorNagarjuna Varma <junky.argonaut@gmail.com>
Sat, 22 Dec 2012 18:35:07 -0500
changeset 116900 bab7ae06e579d274c81c5701ee87e35df8e14265
parent 116899 80c7c3eee490dacd5ade7ce5942730f917ff3ab4
child 116901 adbb1a174e93c85caec379d75a503cac42deb8a7
push id20205
push usermarkcapella@twcny.rr.com
push dateSat, 22 Dec 2012 23:35:44 +0000
treeherdermozilla-inbound@bab7ae06e579 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs785060
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785060 - Check for allocation failure in JS_NewUCStringCopyZ calls; r=Ms2ger
content/html/content/src/nsHTMLMediaElement.cpp
dom/system/OSFileConstants.cpp
xpfe/components/directory/nsDirectoryViewer.cpp
--- a/content/html/content/src/nsHTMLMediaElement.cpp
+++ b/content/html/content/src/nsHTMLMediaElement.cpp
@@ -1487,16 +1487,21 @@ PLDHashOperator
 nsHTMLMediaElement::BuildObjectFromTags(nsCStringHashKey::KeyType aKey,
                                         nsCString aValue,
                                         void* aUserArg)
 {
   MetadataIterCx* args = static_cast<MetadataIterCx*>(aUserArg);
 
   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)) {
     NS_WARNING("Failed to set metadata property");
     args->error = true;
     return PL_DHASH_STOP;
   }
 
--- a/dom/system/OSFileConstants.cpp
+++ b/dom/system/OSFileConstants.cpp
@@ -626,16 +626,17 @@ JSObject *GetOrCreateObjectProperty(JSCo
  */
 bool SetStringProperty(JSContext *cx, JSObject *aObject, const char *aProperty,
                        const nsString aValue)
 {
   if (aValue.IsVoid()) {
     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);
 }
 
 /**
  * Define OS-specific constants.
  *
  * This function creates or uses JS object |OS.Constants| to store
--- a/xpfe/components/directory/nsDirectoryViewer.cpp
+++ b/xpfe/components/directory/nsDirectoryViewer.cpp
@@ -163,16 +163,17 @@ nsHTTPIndex::OnFTPControlLog(bool server
     NS_ENSURE_TRUE(global, NS_OK);
 
     jsval params[2];
 
     nsString unicodeMsg;
     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);
     
     jsval val;
     JS_CallFunctionName(cx,
                         global, 
                         "OnFTPControlLog",