Bug 1294533 - FileReader should start reading data only after allocating the buffer. r=bkelly, a=jcristau
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 05 Jan 2017 17:07:54 +0100
changeset 353430 c23760f94dec504999df4dcb04af5ebd84da9c44
parent 353429 614bfd5e42120c8e3e9e8978a0c1dfeb281603b1
child 353431 4195687bda73679988aaff7b27a8c3b31e38a0fc
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly, jcristau
bugs1294533
milestone52.0a2
Bug 1294533 - FileReader should start reading data only after allocating the buffer. r=bkelly, a=jcristau
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)