mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Stop leaking entire realms via Blob URLs
This patch implements the File API spec's supplemental steps for document's "unloading document cleanup steps" so that we now remove blob URLs associated with the document's relevant settings object when the document is being unloaded. Fixes two realm leaks when running our test suite.
This commit is contained in:
parent
696cf7b9fb
commit
d91d6ee205
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/awesomekling
Commit: d91d6ee205
Pull-request: https://github.com/SerenityOS/serenity/pull/23822
3 changed files with 23 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -7,6 +8,7 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/Crypto/Crypto.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/FileAPI/Blob.h>
|
||||
#include <LibWeb/FileAPI/BlobURLStore.h>
|
||||
#include <LibWeb/HTML/Origin.h>
|
||||
|
@ -89,4 +91,19 @@ ErrorOr<void> remove_entry_from_blob_url_store(StringView url)
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#lifeTime
|
||||
void run_unloading_cleanup_steps(JS::NonnullGCPtr<DOM::Document> document)
|
||||
{
|
||||
// 1. Let environment be the Document's relevant settings object.
|
||||
auto& environment = document->relevant_settings_object();
|
||||
|
||||
// 2. Let store be the user agent’s blob URL store;
|
||||
auto& store = FileAPI::blob_url_store();
|
||||
|
||||
// 3. Remove from store any entries for which the value's environment is equal to environment.
|
||||
store.remove_all_matching([&](auto&, auto& value) {
|
||||
return value.environment == &environment;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue