Index: Source/core/html/parser/HTMLDocumentParser.cpp |
diff --git a/Source/core/html/parser/HTMLDocumentParser.cpp b/Source/core/html/parser/HTMLDocumentParser.cpp |
index 5c78b8da1b9df2032bc0b121f5b8c57315bec37e..e430d15ea5b93ae29149cc2efc4918cb578472e7 100644 |
--- a/Source/core/html/parser/HTMLDocumentParser.cpp |
+++ b/Source/core/html/parser/HTMLDocumentParser.cpp |
@@ -872,6 +872,12 @@ void HTMLDocumentParser::finish() |
// makes sense to call any methods on DocumentParser once it's been stopped. |
// However, FrameLoader::stop calls DocumentParser::finish unconditionally. |
+ // flush may ending up executing arbitrary script, and possibly detach the parser. |
+ RefPtr<HTMLDocumentParser> protect(this); |
+ flush(); |
+ if (isDetached()) |
+ return; |
+ |
// Empty documents never got an append() call, and thus have never started |
// a background parser. In those cases, we ignore shouldUseThreading() |
// and fall through to the non-threading case. |