Fix use after free in mysqlxx::Pool::tryGet()

tryGet() created an Entry object that referenced a Connection, but then
deleted the Connection just before the Entry went out of scope.
This commit is contained in:
Haavard Kvaalen 2021-03-04 15:34:05 +01:00
parent f96892d45c
commit efa94c5735

View File

@ -174,9 +174,11 @@ Pool::Entry Pool::tryGet()
/// Fixme: There is a race condition here b/c we do not synchronize with Pool::Entry's copy-assignment operator
if (connection_ptr->ref_count == 0)
{
Entry res(connection_ptr, this);
if (res.tryForceConnected()) /// Tries to reestablish connection as well
return res;
{
Entry res(connection_ptr, this);
if (res.tryForceConnected()) /// Tries to reestablish connection as well
return res;
}
logger.debug("(%s): Idle connection to MySQL server cannot be recovered, dropping it.", getDescription());