Merge pull request #50334 from valbok/pool-mem-leak

Fix crash when Pool::Entry::disconnect() is called
This commit is contained in:
Kseniia Sumarokova 2023-06-01 18:01:56 +02:00 committed by GitHub
commit 9ff4e6d6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,14 +40,10 @@ void Pool::Entry::decrementRefCount()
{
/// We were the last user of this thread, deinitialize it
mysql_thread_end();
}
else if (data->removed_from_pool)
{
/// data->ref_count == 0 in case we removed connection from pool (see Pool::removeConnection).
chassert(ref_count == 0);
/// In Pool::Entry::disconnect() we remove connection from the list of pool's connections.
/// So now we must deallocate the memory.
::delete data;
if (data->removed_from_pool)
::delete data;
}
}
@ -234,11 +230,8 @@ void Pool::removeConnection(Connection* connection)
std::lock_guard lock(mutex);
if (connection)
{
if (connection->ref_count > 0)
{
if (!connection->removed_from_pool)
connection->conn.disconnect();
connection->ref_count = 0;
}
connections.remove(connection);
connection->removed_from_pool = true;
}