Fix segmentation fault when creating sql tables failed

`GameServer()->OnShutdown(true);` (which would wait on running threads to exit)
wasn't called if an error occured in the server init. Therefore `CServer` was
freed before the init-thread finished executing, causing a use after free from
`CSqlConnector::ms_ppSqlReadServers` pointing to `CServer->m_apSqlReadServers`.
This commit is contained in:
Zwelf 2020-06-18 20:43:19 +02:00
parent 6fcb8abbd0
commit f5ac6eea56

View file

@ -2063,7 +2063,7 @@ int CServer::Run()
GameServer()->OnInit(); GameServer()->OnInit();
if(ErrorShutdown()) if(ErrorShutdown())
{ {
return 1; m_RunServer = false;
} }
str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion()); str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion());
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
@ -2281,6 +2281,7 @@ int CServer::Run()
const char *pDisconnectReason = "Server shutdown"; const char *pDisconnectReason = "Server shutdown";
if(ErrorShutdown()) if(ErrorShutdown())
{ {
dbg_msg("server", "shutdown from game server (%s)", m_aErrorShutdownReason);
pDisconnectReason = m_aErrorShutdownReason; pDisconnectReason = m_aErrorShutdownReason;
} }
// disconnect all clients on shutdown // disconnect all clients on shutdown