From e79d0ccb4ed0cb19a7b6596fd9ceed78fdb5d0aa Mon Sep 17 00:00:00 2001 From: "rpotts%netscape.com" Date: Tue, 10 Nov 1998 07:06:02 +0000 Subject: [PATCH] do not allow the stream listener to be freed during a call to OnDataAvailable... It is possible, that OnStopBinding() wil lbe called while the listener is processing the data (ie. the URL load is interrupted). If this happens, do not free the listener until the OnDataAvailable() call has finished... git-svn-id: svn://10.0.0.236/trunk@14335 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/uriloader/base/nsDocLoader.cpp | 14 +++++++++++++- mozilla/webshell/src/nsDocLoader.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index 22cfa9ed659..c664caea72d 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -1348,7 +1348,19 @@ NS_METHOD nsDocumentBindInfo::OnDataAvailable(nsIURL* aURL, NS_PRECONDITION(nsnull !=m_NextStream, "DocLoader: No stream for document"); if (nsnull != m_NextStream) { - rv = m_NextStream->OnDataAvailable(aURL, aStream, aLength); + /* + * Bump the refcount in case the stream gets destroyed while the data + * is being processed... If Stop(...) is called the stream could be + * freed prematurely :-( + * + * Currently this can happen if javascript loads a new URL + * (via nsIWebShell::LoadURL) during the parse phase... + */ + nsIStreamListener* listener = m_NextStream; + + NS_ADDREF(listener); + rv = listener->OnDataAvailable(aURL, aStream, aLength); + NS_RELEASE(listener); } done: diff --git a/mozilla/webshell/src/nsDocLoader.cpp b/mozilla/webshell/src/nsDocLoader.cpp index 22cfa9ed659..c664caea72d 100644 --- a/mozilla/webshell/src/nsDocLoader.cpp +++ b/mozilla/webshell/src/nsDocLoader.cpp @@ -1348,7 +1348,19 @@ NS_METHOD nsDocumentBindInfo::OnDataAvailable(nsIURL* aURL, NS_PRECONDITION(nsnull !=m_NextStream, "DocLoader: No stream for document"); if (nsnull != m_NextStream) { - rv = m_NextStream->OnDataAvailable(aURL, aStream, aLength); + /* + * Bump the refcount in case the stream gets destroyed while the data + * is being processed... If Stop(...) is called the stream could be + * freed prematurely :-( + * + * Currently this can happen if javascript loads a new URL + * (via nsIWebShell::LoadURL) during the parse phase... + */ + nsIStreamListener* listener = m_NextStream; + + NS_ADDREF(listener); + rv = listener->OnDataAvailable(aURL, aStream, aLength); + NS_RELEASE(listener); } done: