Bug 462728 crash when using alert from docloaderservice onStateChange listener [@ nsJARChannel::OnStartRequest]
authortimeless <timeless@mozdev.org>
Thu, 05 Mar 2009 13:27:48 +0100
changeset 25755 4435f67c38e9047c156c6d5f02092ad8ef5d0a07
parent 25754 5e81fbdd55e4be3884f8aca0c337f0c7a3c9b074
child 25757 3a31158051a4c47cbbcd35e528abbcf154bb7c87
push id5727
push usertimeless@mozdev.org
push dateThu, 05 Mar 2009 10:17:43 +0000
treeherdermozilla-central@4435f67c38e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs462728
milestone1.9.2a1pre
Bug 462728 crash when using alert from docloaderservice onStateChange listener [@ nsJARChannel::OnStartRequest] r=biesi
modules/libjar/nsJARChannel.cpp
--- a/modules/libjar/nsJARChannel.cpp
+++ b/modules/libjar/nsJARChannel.cpp
@@ -689,31 +689,40 @@ nsJARChannel::AsyncOpen(nsIStreamListene
     mIsUnsafe = PR_TRUE;
 
     // Initialize mProgressSink
     NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, mProgressSink);
 
     nsresult rv = EnsureJarInput(PR_FALSE);
     if (NS_FAILED(rv)) return rv;
 
+    // These variables must only be set if we're going to trigger an
+    // OnStartRequest, either from AsyncRead or OnDownloadComplete.
+    mListener = listener;
+    mListenerContext = ctx;
+    mIsPending = PR_TRUE;
     if (mJarInput) {
-        // create input stream pump
+        // create input stream pump and call AsyncRead as a block
         rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mJarInput);
-        if (NS_FAILED(rv)) return rv;
+        if (NS_SUCCEEDED(rv))
+            rv = mPump->AsyncRead(this, nsnull);
 
-        rv = mPump->AsyncRead(this, nsnull);
-        if (NS_FAILED(rv)) return rv;
+        // If we failed to create the pump or initiate the AsyncRead,
+        // then we need to clear these variables.
+        if (NS_FAILED(rv)) {
+            mIsPending = PR_FALSE;
+            mListenerContext = nsnull;
+            mListener = nsnull;
+            return rv;
+        }
     }
 
     if (mLoadGroup)
         mLoadGroup->AddRequest(this, nsnull);
 
-    mListener = listener;
-    mListenerContext = ctx;
-    mIsPending = PR_TRUE;
     return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsIJARChannel
 //-----------------------------------------------------------------------------
 NS_IMETHODIMP
 nsJARChannel::GetIsUnsafe(PRBool *isUnsafe)