1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +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:
Jan de Visser 2021-08-22 13:26:15 -04:00 committed by Andreas Kling
parent c07f91474d
commit c5c7a9d198
2 changed files with 4 additions and 4 deletions

View file

@ -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());