Bug 1294533 - FileReader should start reading data only after allocating the buffer. r=bkelly, a=lizzard
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 05 Jan 2017 17:07:54 +0100
changeset 359313 d78b42d605ca8a6e074db2374978452df508a0d8
parent 359312 fd57670a2f39d1d7c74548879dd378d3efe86e46
child 359314 fb7bda53c7d205cf4a4000acfd83e5b503af800c
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, lizzard
bugs1294533
milestone51.0
Bug 1294533 - FileReader should start reading data only after allocating the buffer. r=bkelly, a=lizzard
dom/base/FileReader.cpp
--- a/dom/base/FileReader.cpp
+++ b/dom/base/FileReader.cpp
@@ -410,32 +410,33 @@ FileReader::ReadFileContent(Blob& aBlob,
   mAsyncStream = do_QueryInterface(wrapper);
   MOZ_ASSERT(mAsyncStream);
 
   mTotal = mBlob->GetSize(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
-  aRv = DoAsyncWait();
-  if (NS_WARN_IF(aRv.Failed())) {
-    return;
-  }
-
-  //FileReader should be in loading state here
-  mReadyState = LOADING;
-  DispatchProgressEvent(NS_LITERAL_STRING(LOADSTART_STR));
-
   if (mDataFormat == FILE_AS_ARRAYBUFFER) {
     mFileData = js_pod_malloc<char>(mTotal);
     if (!mFileData) {
       NS_WARNING("Preallocation failed for ReadFileData");
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     }
   }
+
+  aRv = DoAsyncWait();
+  if (NS_WARN_IF(aRv.Failed())) {
+    FreeFileData();
+    return;
+  }
+
+  //FileReader should be in loading state here
+  mReadyState = LOADING;
+  DispatchProgressEvent(NS_LITERAL_STRING(LOADSTART_STR));
 }
 
 nsresult
 FileReader::GetAsText(Blob *aBlob,
                       const nsACString &aCharset,
                       const char *aFileData,
                       uint32_t aDataLen,
                       nsAString& aResult)