diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp
index 68f86c6503e..f49b0e700cd 100644
--- a/mozilla/parser/htmlparser/src/nsParser.cpp
+++ b/mozilla/parser/htmlparser/src/nsParser.cpp
@@ -299,11 +299,17 @@ nsParser::~nsParser()
}
#endif
-#ifdef DEBUG_mrbkap
- NS_ASSERTION(!mParserContext || !mParserContext->mPrevContext,
- "Leaking parsercontexts");
+#ifdef DEBUG
+ if (mParserContext && mParserContext->mPrevContext) {
+ NS_WARNING("Extra parser contexts still on the parser stack");
+ }
#endif
- delete mParserContext;
+
+ while (mParserContext) {
+ CParserContext *pc = mParserContext->mPrevContext;
+ delete mParserContext;
+ mParserContext = pc;
+ }
if (mFlags & NS_PARSER_FLAG_PENDING_CONTINUE_EVENT) {
NS_ASSERTION(mEventQueue != nsnull, "Event queue is null");
@@ -1343,6 +1349,11 @@ nsParser::Parse(const nsAString& aSourceBuffer,
{
nsresult result = NS_OK;
+ // Don't bother if we're never going to parse this.
+ if (mInternalState == NS_ERROR_HTMLPARSER_STOPPARSING) {
+ return result;
+ }
+
if (!aLastCall && aSourceBuffer.IsEmpty()) {
// Nothing is being passed to the parser so return
// immediately. mUnusedInput will get processed when