From d0fb62d70062ce9b9cb64585d34c6d929814b106 Mon Sep 17 00:00:00 2001 From: "kmcclusk%netscape.com" Date: Wed, 7 Nov 2001 01:02:56 +0000 Subject: [PATCH] Fix leak of parser objects when page load is interrupted by calling nsParser::CancelParsingEvents inside nsParser::Terminate; bug 108049 (patch from aaronr@us.ibm.com) r=harishd sr=attinasi git-svn-id: svn://10.0.0.236/trunk@107527 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/nsParser.cpp | 14 ++++++++++++++ mozilla/parser/htmlparser/src/nsParser.cpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index dee54a0a21e..4485ef06e05 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -1320,7 +1320,13 @@ nsParser::CancelParsingEvents() { if (mEventQueue != nsnull) { mEventQueue->RevokeEvents(this); } + mPendingContinueEvent=PR_FALSE; + /* Since we are taking this off of the queue, we need to do the NS_RELEASE + * that nsParserContinueEvent::HandleEvent would have done. + */ + nsParser* me = this; + NS_RELEASE(me); } return NS_OK; } @@ -1454,6 +1460,14 @@ nsresult nsParser::Terminate(void){ // Hack - Hold a reference until we are completely done... nsCOMPtr kungFuDeathGrip(this); mInternalState=result; + + // CancelParsingEvents must be called to avoid leaking the nsParser object + // @see bug 108049 + // If mPendingContinueEvents is PR_TRUE CancelParsingEvents will reset + // the mPendingContinueEvent to PR_FALSE so DidBuildModel will call + // DidBuildModel on the DTD. Note: The IsComplete() call inside of DidBuildModel + // looks at the mPendingContinueEvents flag. + CancelParsingEvents(); DidBuildModel(result); } } diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index dee54a0a21e..4485ef06e05 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -1320,7 +1320,13 @@ nsParser::CancelParsingEvents() { if (mEventQueue != nsnull) { mEventQueue->RevokeEvents(this); } + mPendingContinueEvent=PR_FALSE; + /* Since we are taking this off of the queue, we need to do the NS_RELEASE + * that nsParserContinueEvent::HandleEvent would have done. + */ + nsParser* me = this; + NS_RELEASE(me); } return NS_OK; } @@ -1454,6 +1460,14 @@ nsresult nsParser::Terminate(void){ // Hack - Hold a reference until we are completely done... nsCOMPtr kungFuDeathGrip(this); mInternalState=result; + + // CancelParsingEvents must be called to avoid leaking the nsParser object + // @see bug 108049 + // If mPendingContinueEvents is PR_TRUE CancelParsingEvents will reset + // the mPendingContinueEvent to PR_FALSE so DidBuildModel will call + // DidBuildModel on the DTD. Note: The IsComplete() call inside of DidBuildModel + // looks at the mPendingContinueEvents flag. + CancelParsingEvents(); DidBuildModel(result); } }