memory leak: properly free terrain_production objects

This commit is contained in:
Enno Rehling 2015-09-11 12:17:35 +02:00
parent 59e2c12605
commit c707ff39b6
2 changed files with 12 additions and 4 deletions

View File

@ -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);
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);
}
}

View File

@ -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;