mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Browser: Prevent moving a Database callback while it is executing
All SQL callbacks here were already moving the to-be-executed callback out of its storage before executing it, except for on_next_result(). This makes on_next_result() do the same move to ensure we do not later attempt to move it while the callback is executing.
This commit is contained in:
parent
fab4d543f6
commit
b9b2274078
Notes:
sideshowbarker
2024-07-19 01:59:31 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/b9b2274078 Pull-request: https://github.com/SerenityOS/serenity/pull/20830
2 changed files with 16 additions and 23 deletions
|
@ -34,39 +34,32 @@ Database::Database(NonnullRefPtr<SQL::SQLClient> sql_client, SQL::ConnectionID c
|
|||
if (result.has_results)
|
||||
return;
|
||||
|
||||
if (auto it = find_pending_execution(result); it != m_pending_executions.end()) {
|
||||
auto in_progress_statement = move(it->value);
|
||||
m_pending_executions.remove(it);
|
||||
|
||||
if (in_progress_statement.on_complete)
|
||||
in_progress_statement.on_complete();
|
||||
if (auto in_progress_statement = take_pending_execution(result); in_progress_statement.has_value()) {
|
||||
if (in_progress_statement->on_complete)
|
||||
in_progress_statement->on_complete();
|
||||
}
|
||||
};
|
||||
|
||||
m_sql_client->on_next_result = [this](auto result) {
|
||||
if (auto it = find_pending_execution(result); it != m_pending_executions.end()) {
|
||||
if (it->value.on_result)
|
||||
it->value.on_result(result.values);
|
||||
if (auto in_progress_statement = take_pending_execution(result); in_progress_statement.has_value()) {
|
||||
if (in_progress_statement->on_result)
|
||||
in_progress_statement->on_result(result.values);
|
||||
|
||||
m_pending_executions.set({ result.statement_id, result.execution_id }, in_progress_statement.release_value());
|
||||
}
|
||||
};
|
||||
|
||||
m_sql_client->on_results_exhausted = [this](auto result) {
|
||||
if (auto it = find_pending_execution(result); it != m_pending_executions.end()) {
|
||||
auto in_progress_statement = move(it->value);
|
||||
m_pending_executions.remove(it);
|
||||
|
||||
if (in_progress_statement.on_complete)
|
||||
in_progress_statement.on_complete();
|
||||
if (auto in_progress_statement = take_pending_execution(result); in_progress_statement.has_value()) {
|
||||
if (in_progress_statement->on_complete)
|
||||
in_progress_statement->on_complete();
|
||||
}
|
||||
};
|
||||
|
||||
m_sql_client->on_execution_error = [this](auto result) {
|
||||
if (auto it = find_pending_execution(result); it != m_pending_executions.end()) {
|
||||
auto in_progress_statement = move(it->value);
|
||||
m_pending_executions.remove(it);
|
||||
|
||||
if (in_progress_statement.on_error)
|
||||
in_progress_statement.on_error(result.error_message);
|
||||
if (auto in_progress_statement = take_pending_execution(result); in_progress_statement.has_value()) {
|
||||
if (in_progress_statement->on_error)
|
||||
in_progress_statement->on_error(result.error_message);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -81,9 +81,9 @@ private:
|
|||
void execute_statement(SQL::StatementID statement_id, Vector<SQL::Value> placeholder_values, PendingExecution pending_execution);
|
||||
|
||||
template<typename ResultData>
|
||||
auto find_pending_execution(ResultData const& result_data)
|
||||
auto take_pending_execution(ResultData const& result_data)
|
||||
{
|
||||
return m_pending_executions.find({ result_data.statement_id, result_data.execution_id });
|
||||
return m_pending_executions.take({ result_data.statement_id, result_data.execution_id });
|
||||
}
|
||||
|
||||
NonnullRefPtr<SQL::SQLClient> m_sql_client;
|
||||
|
|
Loading…
Reference in a new issue