forked from github/server
free multi-level construction correctly, avoid duplication
This commit is contained in:
parent
26f5b592bd
commit
a6ca489d9a
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue