Bug 614958 - Part 2: Protect the destruction of the callback objects the same way as the event sink object to avoid possible deadlock scenarios; r=bzbarsky a=blocking-beta8+

This commit is contained in:
Ehsan Akhgari 2010-12-02 19:22:45 -05:00
Родитель a4cd713d8b
Коммит 5d5fac42ff
1 изменённых файлов: 7 добавлений и 5 удалений

Просмотреть файл

@ -1613,10 +1613,12 @@ nsSocketTransport::OnSocketDetached(PRFileDesc *fd)
// the transport lock) possibly closing the socket. Also release our // the transport lock) possibly closing the socket. Also release our
// listeners to break potential refcount cycles. // listeners to break potential refcount cycles.
// We should be careful not to release mEventSink while we're locked, // We should be careful not to release mEventSink and mCallbacks while
// because releasing it might require acquiring the lock again, so // we're locked, because releasing it might require acquiring the lock
// we just null out mEventSink while we're holding the lock, and let // again, so we just null out mEventSink and mCallbacks while we're
// ourEventSink's destuctor take care of destroying it if needed. // holding the lock, and let the stack based objects' destuctors take
// care of destroying it if needed.
nsCOMPtr<nsIInterfaceRequestor> ourCallbacks;
nsCOMPtr<nsITransportEventSink> ourEventSink; nsCOMPtr<nsITransportEventSink> ourEventSink;
{ {
nsAutoLock lock(mLock); nsAutoLock lock(mLock);
@ -1632,7 +1634,7 @@ nsSocketTransport::OnSocketDetached(PRFileDesc *fd)
// link with UI and security callbacks on next connection attempt // link with UI and security callbacks on next connection attempt
// round. That would lead e.g. to a broken certificate exception page. // round. That would lead e.g. to a broken certificate exception page.
if (NS_FAILED(mCondition)) { if (NS_FAILED(mCondition)) {
mCallbacks = nsnull; mCallbacks.swap(ourCallbacks);
mEventSink.swap(ourEventSink); mEventSink.swap(ourEventSink);
} }
} }