From 976b6aaea171bf79191a92d546a9f7f53e4e5a95 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 29 Oct 2015 11:17:31 +0100 Subject: [PATCH] coverity CID 22593: write to pointer after free github issue #324 use free_land where we need it. --- src/kernel/region.c | 6 +++--- src/kernel/region.h | 1 + src/kernel/save.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index 4b57b9e51..779b45e4a 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -751,7 +751,7 @@ void remove_region(region ** rlist, region * r) deleted_regions = r; } -static void freeland(land_region * lr) +void free_land(land_region * lr) { free(lr->ownership); while (lr->demands) { @@ -817,7 +817,7 @@ void free_region(region * r) last = NULL; free(r->display); if (r->land) - freeland(r->land); + free_land(r->land); if (r->msgs) { free_messagelist(r->msgs->begin); @@ -997,7 +997,7 @@ void terraform_region(region * r, const terrain_type * terrain) region_setinfo(r, NULL); if (r->land != NULL) { i_freeall(&r->land->items); - freeland(r->land); + free_land(r->land); r->land = NULL; } rsettrees(r, 0, 0); diff --git a/src/kernel/region.h b/src/kernel/region.h index 93453364a..b0672e758 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -245,6 +245,7 @@ extern "C" { #endif void free_regions(void); + void free_land(struct land_region * lr); int region_get_morale(const region * r); void region_set_morale(region * r, int morale, int turn); diff --git a/src/kernel/save.c b/src/kernel/save.c index 300555180..c47e10e20 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -840,8 +840,8 @@ static region *readregion(struct gamedata *data, int x, int y) while (r->attribs) a_remove(&r->attribs, r->attribs); if (r->land) { - free(r->land); /* mem leak */ - r->land->demands = 0; /* mem leak */ + free_land(r->land); + r->land = 0; } while (r->resources) { rawmaterial *rm = r->resources;