mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-15 14:02:20 +00:00
SQLServer: Do not capture stack variables by reference in lambdas
If you capture a stack variable by reference in a lamdba definition, and this lambda outlives the scope of the stack variable, this reference may point to garbage when the lambda is executed. Therefore capture as little as possible (typically only ``this``), and what is captured is captured by value
This commit is contained in:
parent
c07f91474d
commit
c5c7a9d198
Notes:
sideshowbarker
2024-07-18 03:03:16 +09:00
Author: https://github.com/JanDeVisser
Commit: c5c7a9d198
Pull-request: https://github.com/SerenityOS/serenity/pull/10094
Reviewed-by: https://github.com/trflynn89 ✅
2 changed files with 4 additions and 4 deletions
|
@ -38,7 +38,7 @@ DatabaseConnection::DatabaseConnection(String database_name, int client_id)
|
|||
|
||||
dbgln_if(SQLSERVER_DEBUG, "DatabaseConnection {} initiating connection with database '{}'", connection_id(), m_database_name);
|
||||
s_connections.set(m_connection_id, *this);
|
||||
deferred_invoke([&] {
|
||||
deferred_invoke([this]() {
|
||||
m_database = SQL::Database::construct(String::formatted("/home/anon/sql/{}.db", m_database_name));
|
||||
m_accept_statements = true;
|
||||
auto client_connection = ClientConnection::client_connection_for(m_client_id);
|
||||
|
@ -53,7 +53,7 @@ void DatabaseConnection::disconnect()
|
|||
{
|
||||
dbgln_if(SQLSERVER_DEBUG, "DatabaseConnection::disconnect(connection_id {}, database '{}'", connection_id(), m_database_name);
|
||||
m_accept_statements = false;
|
||||
deferred_invoke([&] {
|
||||
deferred_invoke([this]() {
|
||||
m_database = nullptr;
|
||||
s_connections.remove(m_connection_id);
|
||||
auto client_connection = ClientConnection::client_connection_for(client_id());
|
||||
|
|
|
@ -60,7 +60,7 @@ void SQLStatement::execute()
|
|||
return;
|
||||
}
|
||||
|
||||
deferred_invoke([&] {
|
||||
deferred_invoke([this]() {
|
||||
auto maybe_error = parse();
|
||||
if (maybe_error.has_value()) {
|
||||
report_error(maybe_error.value());
|
||||
|
@ -107,7 +107,7 @@ void SQLStatement::next()
|
|||
if (m_index < m_result->results().size()) {
|
||||
auto& tuple = m_result->results()[m_index++];
|
||||
client_connection->async_next_result(statement_id(), tuple.to_string_vector());
|
||||
deferred_invoke([&] {
|
||||
deferred_invoke([this]() {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue