From c707ff39b61722af183039c21fb0a5f1b6baa9f3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 11 Sep 2015 12:17:35 +0200 Subject: [PATCH] memory leak: properly free terrain_production objects --- src/kernel/terrain.c | 10 +++++++++- src/kernel/terrain.h | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index f27fe1bd0..e72e94bfa 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -59,10 +59,18 @@ static terrain_type *registered_terrains; void free_terrains(void) { while (registered_terrains) { + int n; terrain_type * t = registered_terrains; registered_terrains = t->next; free(t->_name); - free(t->production); + if (t->production) { + for (n = 0; t->production[n].type; ++n) { + free(t->production[n].base); + free(t->production[n].divisor); + free(t->production[n].startlevel); + } + free(t->production); + } free(t); } } diff --git a/src/kernel/terrain.h b/src/kernel/terrain.h index 64b0aa299..945d07794 100644 --- a/src/kernel/terrain.h +++ b/src/kernel/terrain.h @@ -51,9 +51,9 @@ extern "C" { typedef struct terrain_production { const struct resource_type *type; - const char *startlevel; - const char *base; - const char *divisor; + char *startlevel; + char *base; + char *divisor; float chance; } terrain_production;