Bug 1226580 - in case of OOM new fails so exit function with errro code, expected valid pointer. r?seth@mozilla.com draft
authorBogdan Postelnicu <bogdan.postelnicu@softvision.ro>
Wed, 13 Jan 2016 16:04:26 +0200
changeset 321390 a150d8b63e730aefdd5460802e0b201e450a88e7
parent 321389 1d250005d87eb2c32603dc99d11468fd57ade517
child 512891 37e1d7a90f1073c96f2ea79751719d89ed79c3d4
push id9367
push userbmo:bogdan.postelnicu@softvision.ro
push dateWed, 13 Jan 2016 14:05:23 +0000
reviewersseth
bugs1226580
milestone46.0a1
Bug 1226580 - in case of OOM new fails so exit function with errro code, expected valid pointer. r?seth@mozilla.com
image/imgLoader.cpp
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1032,16 +1032,18 @@ imgLoader::CreateNewProxyForRequest(imgR
 
   /* XXX If we move decoding onto separate threads, we should save off the
      calling thread here and pass it off to |proxyRequest| so that it call
      proxy calls to |aObserver|.
    */
 
   RefPtr<imgRequestProxy> proxyRequest = new imgRequestProxy();
 
+  NS_ENSURE_ARG_POINTER(proxyRequest.get());
+
   /* It is important to call |SetLoadFlags()| before calling |Init()| because
      |Init()| adds the request to the loadgroup.
    */
   proxyRequest->SetLoadFlags(aLoadFlags);
 
   RefPtr<ImageURL> uri;
   aRequest->GetURI(getter_AddRefs(uri));
 
@@ -2393,17 +2395,22 @@ imgLoader::LoadImageWithChannel(nsIChann
 
     // this should fire an OnStopRequest
     channel->Cancel(NS_ERROR_PARSED_DATA_CACHED);
 
     *listener = nullptr; // give them back a null nsIStreamListener
 
     rv = CreateNewProxyForRequest(request, loadGroup, aObserver,
                                   requestFlags, _retval);
-    static_cast<imgRequestProxy*>(*_retval)->NotifyListener();
+
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+        return rv;
+    }
+
+    (*_retval)->NotifyListener();
   } else {
     // We use originalURI here to fulfil the imgIRequest contract on GetURI.
     nsCOMPtr<nsIURI> originalURI;
     channel->GetOriginalURI(getter_AddRefs(originalURI));
 
     // XXX(seth): We should be able to just use |key| here, except that |key| is
     // constructed above with the *current URI* and not the *original URI*. I'm
     // pretty sure this is a bug, and it's preventing us from ever getting a