Bug 1278452 - Add some null checks when getting streams. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 07 Jun 2016 16:03:32 +1000
changeset 326093 45ea273f14d1f1e17c352d7a5df4f1deff43283e
parent 326092 9b6d23819097bb067fd9bea9b9d45df0f7fdc062
child 326094 2202233b5b183143c85ab7a65b84a90003c262b3
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1278452
milestone50.0a1
Bug 1278452 - Add some null checks when getting streams. r=froydnj.
dom/events/DataTransfer.cpp
startupcache/StartupCacheUtils.cpp
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1488,21 +1488,22 @@ DataTransfer::FillInExternalCustomTypes(
   nsAutoCString str;
   str.Adopt(chrs, len);
 
   nsCOMPtr<nsIInputStream> stringStream;
   NS_NewCStringInputStream(getter_AddRefs(stringStream), str);
 
   nsCOMPtr<nsIBinaryInputStream> stream =
     do_CreateInstance("@mozilla.org/binaryinputstream;1");
-  stream->SetInputStream(stringStream);
   if (!stream) {
     return;
   }
 
+  stream->SetInputStream(stringStream);
+
   uint32_t type;
   do {
     stream->Read32(&type);
     if (type == eCustomClipboardTypeId_String) {
       uint32_t formatLength;
       stream->Read32(&formatLength);
       char* formatBytes;
       stream->ReadBytes(formatLength, &formatBytes);
--- a/startupcache/StartupCacheUtils.cpp
+++ b/startupcache/StartupCacheUtils.cpp
@@ -17,24 +17,27 @@
 
 namespace mozilla {
 namespace scache {
 
 NS_EXPORT nsresult
 NewObjectInputStreamFromBuffer(UniquePtr<char[]> buffer, uint32_t len, 
                                nsIObjectInputStream** stream)
 {
-  nsCOMPtr<nsIStringInputStream> stringStream
-    = do_CreateInstance("@mozilla.org/io/string-input-stream;1");
-  nsCOMPtr<nsIObjectInputStream> objectInput 
-    = do_CreateInstance("@mozilla.org/binaryinputstream;1");
-  
+  nsCOMPtr<nsIStringInputStream> stringStream =
+    do_CreateInstance("@mozilla.org/io/string-input-stream;1");
+  NS_ENSURE_TRUE(stringStream, NS_ERROR_FAILURE);
+
+  nsCOMPtr<nsIObjectInputStream> objectInput =
+    do_CreateInstance("@mozilla.org/binaryinputstream;1");
+  NS_ENSURE_TRUE(objectInput, NS_ERROR_FAILURE);
+
   stringStream->AdoptData(buffer.release(), len);
   objectInput->SetInputStream(stringStream);
-  
+
   objectInput.forget(stream);
   return NS_OK;
 }
 
 NS_EXPORT nsresult
 NewObjectOutputWrappedStorageStream(nsIObjectOutputStream **wrapperStream,
                                     nsIStorageStream** stream,
                                     bool wantDebugStream)