Browse Source

WebContent: Remove pending file requests before invoking their callbacks

It's currently possible for the callback of a file request to request
more file objects. This could cause the hash map storing these requests
to be rehashed while one of its callbacks is being invoked. AK::Function
explicitly forbids this with an assertion.

Instead, remove the callback from the hash map before invoking the
callback function.
Timothy Flynn 2 years ago
parent
commit
7c1fe32af3
1 changed files with 1 additions and 2 deletions
  1. 1 2
      Userland/Services/WebContent/ConnectionFromClient.cpp

+ 1 - 2
Userland/Services/WebContent/ConnectionFromClient.cpp

@@ -562,13 +562,12 @@ Messages::WebContentServer::GetSessionStorageEntriesResponse ConnectionFromClien
 
 void ConnectionFromClient::handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id)
 {
-    auto file_request = m_requested_files.get(request_id);
+    auto file_request = m_requested_files.take(request_id);
 
     VERIFY(file_request.has_value());
     VERIFY(file_request.value().on_file_request_finish);
 
     file_request.value().on_file_request_finish(error != 0 ? Error::from_errno(error) : ErrorOr<i32> { file->take_fd() });
-    m_requested_files.remove(request_id);
 }
 
 void ConnectionFromClient::request_file(Web::FileRequest file_request)