From 953c19bdb704d9aa0da2d59272eca5e07fda641d Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 19 Aug 2023 14:55:49 +0200 Subject: [PATCH] LibWeb: Clear callbacks in `SharedImageRequest` after request is done Callbacks registered within the SharedImageRequest can be removed after the request has been completed. This resolves the GC memory leak issue that occurs due to a cyclic dependency, where the callback captures the image request while being owned by the image request at the same time. --- Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp index e4a10df167..d24c305515 100644 --- a/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp +++ b/Userland/Libraries/LibWeb/HTML/SharedImageRequest.cpp @@ -160,6 +160,7 @@ void SharedImageRequest::handle_successful_fetch(AK::URL const& url_string, Stri if (callback.on_finish) callback.on_finish(); } + m_callbacks.clear(); } void SharedImageRequest::handle_failed_fetch() @@ -169,6 +170,7 @@ void SharedImageRequest::handle_failed_fetch() if (callback.on_fail) callback.on_fail(); } + m_callbacks.clear(); } bool SharedImageRequest::needs_fetching() const