Bug 1396300 - Use fallible allocation in GetAsStream. r=bkelly
authorShawn Huang <shuang@mozilla.com>
Fri, 08 Sep 2017 11:59:46 +0800
changeset 429133 6b1112ce0727a6ff4a8c1e239685a165bdbb0d89
parent 429132 3cccaa8e877760f9a6f4f0d124ab816290e49f4d
child 429134 252f32919ce2a7ab1f5891189525bb31b4e27f79
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1396300
milestone57.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 1396300 - Use fallible allocation in GetAsStream. r=bkelly
dom/fetch/BodyExtractor.cpp
--- a/dom/fetch/BodyExtractor.cpp
+++ b/dom/fetch/BodyExtractor.cpp
@@ -130,17 +130,19 @@ BodyExtractor<nsIDocument>::GetAsStream(
 
 template<> nsresult
 BodyExtractor<const nsAString>::GetAsStream(nsIInputStream** aResult,
                                             uint64_t* aContentLength,
                                             nsACString& aContentTypeWithCharset,
                                             nsACString& aCharset) const
 {
   nsCString encoded;
-  CopyUTF16toUTF8(*mBody, encoded);
+  if (!CopyUTF16toUTF8(*mBody, encoded, fallible)) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   nsresult rv = NS_NewCStringInputStream(aResult, encoded);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   *aContentLength = encoded.Length();
   aContentTypeWithCharset.AssignLiteral("text/plain;charset=UTF-8");