From a5f3f332ed79e02f21fd0167a5213e03e26fbadf Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 19 Oct 2019 09:43:05 +0200 Subject: [PATCH] LibHTML: Ignore completed image loads for already-destroyed 's Capture a weak pointer to the element and pass that to the load finish callback in HTMLImageElement::load_image(). This allows us to ignore completed loads if the element is no longer around. --- Libraries/LibHTML/DOM/HTMLImageElement.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp index 3ae099290b..5cf0c92381 100644 --- a/Libraries/LibHTML/DOM/HTMLImageElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp @@ -23,7 +23,11 @@ void HTMLImageElement::parse_attribute(const String& name, const String& value) void HTMLImageElement::load_image(const String& src) { URL src_url = document().complete_url(src); - ResourceLoader::the().load(src_url, [this](auto data) { + ResourceLoader::the().load(src_url, [this, weak_element = make_weak_ptr()](auto data) { + if (!weak_element) { + dbg() << "HTMLImageElement: Load completed after element destroyed."; + return; + } if (data.is_null()) { dbg() << "HTMLImageElement: Failed to load " << this->src(); return;