summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-12-24 23:01:16 +0000
committersmatz <smatz@openttd.org>2008-12-24 23:01:16 +0000
commit2eee9bdc3bbe599c9b4a5f2c12e5ac6e7dfbba4b (patch)
tree28ddc5443cd2d45b2e124f1be86a84d4f06ac1ab /src
parent24ffb8bbbacb0b77f7264ee87eb8e9ef0abaaa26 (diff)
downloadopenttd-2eee9bdc3bbe599c9b4a5f2c12e5ac6e7dfbba4b.tar.xz
(svn r14739) -Fix (r13675): when a static GRF was forcibly disabled, wrong data was released, causing memory leaks and wrong behaviour or crashes
Diffstat (limited to 'src')
-rw-r--r--src/newgrf.cpp29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 703b3f817..a832873ee 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -240,20 +240,20 @@ static GRFFile *GetFileByFilename(const char *filename)
}
/** Reset all NewGRFData that was used only while processing data */
-static void ClearTemporaryNewGRFData()
+static void ClearTemporaryNewGRFData(GRFFile *gf)
{
/* Clear the GOTO labels used for GRF processing */
- for (GRFLabel *l = _cur_grffile->label; l != NULL;) {
+ for (GRFLabel *l = gf->label; l != NULL;) {
GRFLabel *l2 = l->next;
free(l);
l = l2;
}
- _cur_grffile->label = NULL;
+ gf->label = NULL;
/* Clear the list of spritegroups */
- free(_cur_grffile->spritegroups);
- _cur_grffile->spritegroups = NULL;
- _cur_grffile->spritegroups_count = 0;
+ free(gf->spritegroups);
+ gf->spritegroups = NULL;
+ gf->spritegroups_count = 0;
}
@@ -3882,7 +3882,7 @@ static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
c->error->severity = STR_NEWGRF_ERROR_MSG_FATAL;
c->error->message = STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(GetFileByGRFID(c->grfid));
_skip_sprites = -1;
}
@@ -4042,7 +4042,7 @@ static void SkipIf(byte *buf, size_t len)
/* If an action 8 hasn't been encountered yet, disable the grf. */
if (_cur_grfconfig->status != GCS_ACTIVATED) {
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
}
}
}
@@ -4215,7 +4215,7 @@ static void GRFLoadError(byte *buf, size_t len)
/* This is a fatal error, so make sure the GRF is deactivated and no
* more of it gets loaded. */
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
_skip_sprites = -1;
}
@@ -4398,7 +4398,7 @@ static uint32 PerformGRM(uint32 *grm, uint16 num_ids, uint16 count, uint8 op, ui
/* Deactivate GRF */
grfmsg(0, "ParamSet: GRM: Unable to allocate %d %s, deactivating", count, type);
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
_skip_sprites = -1;
return UINT_MAX;
}
@@ -4477,7 +4477,7 @@ static void ParamSet(byte *buf, size_t len)
if (_cur_spriteid + count >= 16384) {
grfmsg(0, "ParamSet: GRM: Unable to allocate %d sprites; try changing NewGRF order", count);
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
_skip_sprites = -1;
return;
}
@@ -4843,7 +4843,7 @@ static void FeatureTownName(byte *buf, size_t len)
grfmsg(0, "FeatureTownName: definition 0x%02X doesn't exist, deactivating", ref_id);
DelGRFTownName(grfid);
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
_skip_sprites = -1;
return;
}
@@ -5134,7 +5134,7 @@ static void TranslateGRFStrings(byte *buf, size_t len)
_cur_grfconfig->error = error;
_cur_grfconfig->status = GCS_DISABLED;
- ClearTemporaryNewGRFData();
+ ClearTemporaryNewGRFData(_cur_grffile);
_skip_sprites = -1;
return;
}
@@ -6077,7 +6077,8 @@ void LoadNewGRF(uint load_index, uint file_index)
SetBit(c->flags, GCF_RESERVED);
} else if (stage == GLS_ACTIVATION) {
ClrBit(c->flags, GCF_RESERVED);
- ClearTemporaryNewGRFData();
+ assert(GetFileByGRFID(c->grfid) == _cur_grffile);
+ ClearTemporaryNewGRFData(_cur_grffile);
BuildCargoTranslationMap();
DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
}