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 326249 53a8e50cdaf84d4fb9ef276b0bae7e7027416a3b
parent 326248 93d727dc3fb472708069ff569f730cf7de1acc0a
child 326250 13f145c74a334e53c13ca67eb5ec09d141a4af67
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, ritu
bugs1269365
milestone47.0
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;
   }