Fix crash when using session after calling session:close()

If session_backend dtor threw an exception, backEnd_ remained pointing
at an already destroyed object. Fix this by resetting it first in any
case and deleting the object pointed to by it later.

This notably affected session's own reconnect() function which could
crash if the connection to the server was broken -- which is precisely
when it's likely to be called.
This commit is contained in:
Vadim Zeitlin
2026-01-14 00:08:39 +01:00
parent 739815ba08
commit 5c00ccb32a

View File

@@ -298,15 +298,16 @@ void session::open(std::string const & connectString)
void session::close()
{
auto* const backEnd = backEnd_;
backEnd_ = NULL;
if (isFromPool_)
{
pool_->at(poolPosition_).close();
backEnd_ = NULL;
}
else
{
delete backEnd_;
backEnd_ = NULL;
delete backEnd;
}
}