Bug 849456 - Fix a potential NULL deref on OOM. r=mrosenberg
authorTerrence Cole <terrence@mozilla.com>
Fri, 08 Mar 2013 17:44:09 -0800
changeset 124294 edf62f27b3c00105179e4759adb0fb591b1924f9
parent 124293 be905015b2535382160108b99f6b7a49595cd855
child 124295 e38c5c3468409bdfcdf8381f6af07f55c413d0e8
push id24412
push userryanvm@gmail.com
push dateSun, 10 Mar 2013 00:01:53 +0000
treeherdermozilla-central@9e6232e86000 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrosenberg
bugs849456
milestone22.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 849456 - Fix a potential NULL deref on OOM. r=mrosenberg
js/src/vm/CharacterEncoding.cpp
--- a/js/src/vm/CharacterEncoding.cpp
+++ b/js/src/vm/CharacterEncoding.cpp
@@ -147,15 +147,17 @@ JS::TwoByteCharsToNewUTF8CharsZ(JSContex
     JS_ASSERT(cx);
 
     /* Get required buffer size. */
     jschar *str = tbchars.start().get();
     size_t len = GetDeflatedUTF8StringLength(cx, str, tbchars.length());
 
     /* Allocate buffer. */
     unsigned char *utf8 = cx->pod_malloc<unsigned char>(len + 1);
+    if (!utf8)
+        return UTF8CharsZ();
 
     /* Encode to UTF8. */
     DeflateStringToUTF8Buffer(cx, str, tbchars.length(), (char *)utf8, &len);
     utf8[len] = '\0';
 
     return UTF8CharsZ(utf8, len);
 }