coverity CID 22593: write to pointer after free

github issue #324
use free_land where we need it.
This commit is contained in:
Enno Rehling 2015-10-29 11:17:31 +01:00
parent c298b7fd74
commit 976b6aaea1
3 changed files with 6 additions and 5 deletions

View File

@ -751,7 +751,7 @@ void remove_region(region ** rlist, region * r)
deleted_regions = r; deleted_regions = r;
} }
static void freeland(land_region * lr) void free_land(land_region * lr)
{ {
free(lr->ownership); free(lr->ownership);
while (lr->demands) { while (lr->demands) {
@ -817,7 +817,7 @@ void free_region(region * r)
last = NULL; last = NULL;
free(r->display); free(r->display);
if (r->land) if (r->land)
freeland(r->land); free_land(r->land);
if (r->msgs) { if (r->msgs) {
free_messagelist(r->msgs->begin); free_messagelist(r->msgs->begin);
@ -997,7 +997,7 @@ void terraform_region(region * r, const terrain_type * terrain)
region_setinfo(r, NULL); region_setinfo(r, NULL);
if (r->land != NULL) { if (r->land != NULL) {
i_freeall(&r->land->items); i_freeall(&r->land->items);
freeland(r->land); free_land(r->land);
r->land = NULL; r->land = NULL;
} }
rsettrees(r, 0, 0); rsettrees(r, 0, 0);

View File

@ -245,6 +245,7 @@ extern "C" {
#endif #endif
void free_regions(void); void free_regions(void);
void free_land(struct land_region * lr);
int region_get_morale(const region * r); int region_get_morale(const region * r);
void region_set_morale(region * r, int morale, int turn); void region_set_morale(region * r, int morale, int turn);

View File

@ -840,8 +840,8 @@ static region *readregion(struct gamedata *data, int x, int y)
while (r->attribs) while (r->attribs)
a_remove(&r->attribs, r->attribs); a_remove(&r->attribs, r->attribs);
if (r->land) { if (r->land) {
free(r->land); /* mem leak */ free_land(r->land);
r->land->demands = 0; /* mem leak */ r->land = 0;
} }
while (r->resources) { while (r->resources) {
rawmaterial *rm = r->resources; rawmaterial *rm = r->resources;