free multi-level construction correctly, avoid duplication

This commit is contained in:
Enno Rehling 2015-10-13 22:56:16 +02:00
parent 26f5b592bd
commit a6ca489d9a
4 changed files with 12 additions and 8 deletions

View File

@ -977,3 +977,12 @@ void continue_ship(unit * u, int want)
build_ship(u, sh, want); build_ship(u, sh, want);
} }
void free_construction(struct construction *cons)
{
while (cons) {
construction *next = cons->improvement;
free(cons->materials);
free(cons);
cons = next;
}
}

View File

@ -65,6 +65,7 @@ extern "C" {
} construction; } construction;
void free_construction(struct construction *cons);
extern int destroy_cmd(struct unit *u, struct order *ord); extern int destroy_cmd(struct unit *u, struct order *ord);
extern int leave_cmd(struct unit *u, struct order *ord); extern int leave_cmd(struct unit *u, struct order *ord);

View File

@ -94,10 +94,7 @@ void bt_register(building_type * type)
void free_buildingtype(void *ptr) { void free_buildingtype(void *ptr) {
building_type *btype = (building_type *)ptr; building_type *btype = (building_type *)ptr;
if (btype->construction) { free_construction(btype->construction);
free(btype->construction->materials);
free(btype->construction);
}
free(btype->_name); free(btype->_name);
free(btype); free(btype);
} }

View File

@ -245,10 +245,7 @@ static void free_shiptype(void *ptr) {
ship_type *stype = (ship_type *)ptr; ship_type *stype = (ship_type *)ptr;
free(stype->_name); free(stype->_name);
free(stype->coasts); free(stype->coasts);
if (stype->construction) { free_construction(stype->construction);
free(stype->construction->materials);
free(stype->construction);
}
free(stype); free(stype);
} }