1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-20 13:09:15 +00:00

(svn r22064) -Fix [FS#4497] (r21399): crash when disconnecting and reconnecting while the server is still saving the savegame

This commit is contained in:
rubidium
2011-02-11 23:20:35 +00:00
parent 1dc5ba2210
commit d8cada7563
2 changed files with 19 additions and 7 deletions

View File

@@ -69,7 +69,6 @@ struct PacketWriter : SaveFilter {
/** Make sure everything is cleaned up. */
~PacketWriter()
{
/* Prevent double frees. */
if (this->cs != NULL) {
if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
@@ -99,7 +98,8 @@ struct PacketWriter : SaveFilter {
/* virtual */ void Write(byte *buf, size_t size)
{
if (this->cs == NULL) return;
/* We want to abort the saving when the socket is closed. */
if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->current == NULL) this->current = new Packet(PACKET_SERVER_MAP_DATA);
@@ -125,7 +125,8 @@ struct PacketWriter : SaveFilter {
/* virtual */ void Finish()
{
if (this->cs == NULL) return;
/* We want to abort the saving when the socket is closed. */
if (this->cs == NULL) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
if (this->cs->savegame_mutex != NULL) this->cs->savegame_mutex->BeginCritical();
@@ -181,6 +182,10 @@ ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
if (this->savegame != NULL) this->savegame->cs = NULL;
if (this->savegame_mutex != NULL) this->savegame_mutex->EndCritical();
/* Make sure the saving is completely cancelled. */
if (this->savegame != NULL) WaitTillSaved();
delete this->savegame_mutex;
}