summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-08-06 07:15:17 +0000
committertron <tron@openttd.org>2005-08-06 07:15:17 +0000
commiteb826dfb66deedcc73932d4afec01f94b2725d3a (patch)
treeac42e91f984bfbcfe8072ba44abb24cf1816fae4
parent747a0f6a55cfb40cdf6e66ca8ae29bc0d4517274 (diff)
downloadopenttd-eb826dfb66deedcc73932d4afec01f94b2725d3a.tar.xz
(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
-rw-r--r--saveload.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/saveload.c b/saveload.c
index a4ef8c80d..73928c0c6 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1245,8 +1245,6 @@ static void* SaveFileToDisk(void* arg)
tmp = _sl.buf;
- SaveFileStart();
-
/* XXX - Setup setjmp error handler if an error occurs anywhere deep during
* loading/saving execute a longjmp() and continue execution here */
if (setjmp(_sl.excpt)) {
@@ -1325,6 +1323,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
WaitTillSaved();
// nonsense to do an autosave while we were still saving our game, so skip it
if (_do_autosave) return SL_OK;
+ } else {
+ WaitTillSaved();
}
/* Load a TTDLX or TTDPatch game */
@@ -1390,6 +1390,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
SlWriteFill(); // flush the save buffer
/* Write to file */
+ SaveFileStart();
if (_network_server ||
(save_thread = OTTDCreateThread(&SaveFileToDisk, NULL)) == NULL) {
DEBUG(misc, 1) ("cannot create savegame thread, reverting to single-threaded mode...");