Bug 1269365 - Part 2 - Make ParamTraits<nsTArray<E>>::Read use infallible allocation. r=froydnj, a=ritu
authorAndrew McCreight <continuation@gmail.com>
Tue, 03 May 2016 09:29:39 -0700
changeset 332832 6983c68ea3d0ba0a202d7da785a4886fa09d5f63
parent 332831 3aa4f99aeb0e022e47cbb26c6fcb535fd024933f
child 332833 4697aa21b170fd9f0d0ff617ad2bf2d3160cf2a8
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, ritu
bugs1269365
milestone48.0a2
Bug 1269365 - Part 2 - Make ParamTraits<nsTArray<E>>::Read use infallible allocation. r=froydnj, a=ritu This will turn allocation failures during deserialization from IPC FatalError crashes into OOM crashes.
ipc/glue/IPCMessageUtils.h
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -450,16 +450,18 @@ struct ParamTraits<nsTArray<E>>
       aMsg->WriteBytes(aParam.Elements(), pickledLength);
     } else {
       for (uint32_t index = 0; index < length; index++) {
         WriteParam(aMsg, aParam[index]);
       }
     }
   }
 
+  // This method uses infallible allocation so that an OOM failure will
+  // show up as an OOM crash rather than an IPC FatalError.
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
     uint32_t length;
     if (!ReadParam(aMsg, aIter, &length)) {
       return false;
     }
 
     if (sUseWriteBytes) {
@@ -468,30 +470,24 @@ struct ParamTraits<nsTArray<E>>
         return false;
       }
 
       const char* outdata;
       if (!aMsg->ReadBytes(aIter, &outdata, pickledLength)) {
         return false;
       }
 
-      E* elements = aResult->AppendElements(length, mozilla::fallible);
-      if (!elements) {
-        return false;
-      }
+      E* elements = aResult->AppendElements(length);
 
       memcpy(elements, outdata, pickledLength);
     } else {
-      if (!aResult->SetCapacity(length, mozilla::fallible)) {
-        return false;
-      }
+      aResult->SetCapacity(length);
 
       for (uint32_t index = 0; index < length; index++) {
-        E* element = aResult->AppendElement(mozilla::fallible);
-        MOZ_ASSERT(element);
+        E* element = aResult->AppendElement();
         if (!ReadParam(aMsg, aIter, element)) {
           return false;
         }
       }
     }
 
     return true;
   }