From 84930cd3ec837f309f4f9cc976e9413c7b5ea9f7 Mon Sep 17 00:00:00 2001 From: "dbaron@dbaron.org" Date: Mon, 17 Sep 2007 17:31:37 -0700 Subject: [PATCH] Fix leak of mPendingHTTPRequest in nsSSLThread::rememberPendingHTTPRequest by converting it to an nsCOMPtr. b=394528 r=kengert sr=bzbarsky a=bsmedberg --- security/manager/ssl/src/nsSSLThread.cpp | 14 ++++---------- security/manager/ssl/src/nsSSLThread.h | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/security/manager/ssl/src/nsSSLThread.cpp b/security/manager/ssl/src/nsSSLThread.cpp index c6ba6077c104..fd60e18e1cfe 100644 --- a/security/manager/ssl/src/nsSSLThread.cpp +++ b/security/manager/ssl/src/nsSSLThread.cpp @@ -48,8 +48,7 @@ extern PRLogModuleInfo* gPIPNSSLog; nsSSLThread::nsSSLThread() : mBusySocket(nsnull), - mSocketScheduledToBeDestroyed(nsnull), - mPendingHTTPRequest(nsnull) + mSocketScheduledToBeDestroyed(nsnull) { NS_ASSERTION(!ssl_thread_singleton, "nsSSLThread is a singleton, caller attempts to create another instance!"); @@ -379,7 +378,7 @@ PRStatus nsSSLThread::requestClose(nsNSSSocketInfo *si) return PR_FAILURE; PRBool close_later = PR_FALSE; - nsIRequest* requestToCancel = nsnull; + nsCOMPtr requestToCancel; { nsAutoLock threadLock(ssl_thread_singleton->mMutex); @@ -395,8 +394,7 @@ PRStatus nsSSLThread::requestClose(nsNSSSocketInfo *si) if (ssl_thread_singleton->mPendingHTTPRequest) { - requestToCancel = ssl_thread_singleton->mPendingHTTPRequest; - ssl_thread_singleton->mPendingHTTPRequest = nsnull; + requestToCancel.swap(ssl_thread_singleton->mPendingHTTPRequest); } close_later = PR_TRUE; @@ -417,7 +415,7 @@ PRStatus nsSSLThread::requestClose(nsNSSSocketInfo *si) NS_WARNING("Attempt to close SSL socket from a thread that is not the main thread. Can not cancel pending HTTP request from NSS"); } - NS_RELEASE(requestToCancel); + requestToCancel = nsnull; } if (!close_later) @@ -1129,7 +1127,6 @@ void nsSSLThread::rememberPendingHTTPRequest(nsIRequest *aRequest) nsAutoLock threadLock(ssl_thread_singleton->mMutex); - NS_IF_ADDREF(aRequest); ssl_thread_singleton->mPendingHTTPRequest = aRequest; } @@ -1143,9 +1140,6 @@ void nsSSLThread::cancelPendingHTTPRequest() if (ssl_thread_singleton->mPendingHTTPRequest) { ssl_thread_singleton->mPendingHTTPRequest->Cancel(NS_ERROR_ABORT); - - NS_RELEASE(ssl_thread_singleton->mPendingHTTPRequest); - ssl_thread_singleton->mPendingHTTPRequest = nsnull; } } diff --git a/security/manager/ssl/src/nsSSLThread.h b/security/manager/ssl/src/nsSSLThread.h index e72062fcafc7..5e60f11a52a3 100644 --- a/security/manager/ssl/src/nsSSLThread.h +++ b/security/manager/ssl/src/nsSSLThread.h @@ -79,7 +79,7 @@ private: // As this HTTP request depends on some original SSL socket, // we can use this handle to cancel the dependent HTTP request, // should we be asked to close the original SSL socket. - nsIRequest* mPendingHTTPRequest; + nsCOMPtr mPendingHTTPRequest; virtual void Run(void);