소스 검색

LibHTML: Ignore completed image loads for already-destroyed <img>'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 <img> element is no longer around.
Andreas Kling 5 년 전
부모
커밋
a5f3f332ed
1개의 변경된 파일5개의 추가작업 그리고 1개의 파일을 삭제
  1. 5 1
      Libraries/LibHTML/DOM/HTMLImageElement.cpp

+ 5 - 1
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;