summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2006-12-20 23:44:39 +0000
committerrubidium <rubidium@openttd.org>2006-12-20 23:44:39 +0000
commit0f06c40be7ede24764656bb0f8ffd8370b518bb4 (patch)
tree16e807ee5df837dc1e887b4f66066ae9c463f348
parent2306f64c38772cc69ee525d24cc2d93017d4a162 (diff)
downloadopenttd-0f06c40be7ede24764656bb0f8ffd8370b518bb4.tar.xz
(svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
-rw-r--r--newgrf_config.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/newgrf_config.c b/newgrf_config.c
index 6caec3e04..f1b9b00ea 100644
--- a/newgrf_config.c
+++ b/newgrf_config.c
@@ -163,9 +163,17 @@ bool IsGoodGRFConfigList(void)
res = false;
} else {
DEBUG(grf, 1) ("[GRF] Loading GRF %08X from %s", BSWAP32(c->grfid), f->filename);
- c->filename = strdup(f->filename);
- c->name = strdup(f->name);
- c->info = strdup(f->info);
+ /* The filename could be the filename as in the savegame. As we need
+ * to load the GRF here, we need the correct filename, so overwrite that
+ * in any case and set the name and info when it is not set already.
+ * When the GCF_COPY flag is set, it is certain that the filename is
+ * already a local one, so there is no need to replace it. */
+ if (!HASBIT(c->flags, GCF_COPY)) {
+ free(c->filename);
+ c->filename = strdup(f->filename);
+ if (c->name == NULL) c->name = strdup(f->name);
+ if (c->info == NULL) c->info = strdup(f->info);
+ }
}
}