diff --git a/src/eressea.c b/src/eressea.c index 7dff11574..c1ae4d73a 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -55,10 +55,6 @@ void game_done(void) free_functions(); free_config(); free_locales(); - message_done(); - equipment_done(); - reports_done(); - curses_done(); kernel_done(); } diff --git a/src/kernel/config.c b/src/kernel/config.c index e45ffdde9..89d816f0f 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -401,24 +401,24 @@ building *largestbuilding(const region * r, cmp_building_cb cmp_gt, static const char *forbidden[] = { "t", "te", "tem", "temp", NULL }; // PEASANT: "b", "ba", "bau", "baue", "p", "pe", "pea", "peas" +static int *forbidden_ids; int forbiddenid(int id) { - static int *forbid = NULL; static size_t len; size_t i; if (id <= 0) return 1; - if (!forbid) { + if (!forbidden_ids) { while (forbidden[len]) ++len; - forbid = calloc(len, sizeof(int)); + forbidden_ids = calloc(len, sizeof(int)); for (i = 0; i != len; ++i) { - forbid[i] = atoi36(forbidden[i]); + forbidden_ids[i] = atoi36(forbidden[i]); } } for (i = 0; i != len; ++i) - if (id == forbid[i]) + if (id == forbidden_ids[i]) return 1; return 0; } @@ -739,8 +739,15 @@ void kernel_done(void) /* calling this function releases memory assigned to static variables, etc. * calling it is optional, e.g. a release server will most likely not do it. */ + xml_done(); + attrib_done(); + item_done(); + message_done(); + equipment_done(); + reports_done(); + curses_done(); + crmessage_done(); translation_done(); - free_attribs(); } #ifndef HAVE_STRDUP @@ -1079,7 +1086,6 @@ void free_config(void) { void free_gamedata(void) { int i; - free_donations(); for (i = 0; i != MAXLOCALES; ++i) { if (defaults[i]) { @@ -1087,6 +1093,10 @@ void free_gamedata(void) defaults[i] = 0; } } + free(forbidden_ids); + forbidden_ids = NULL; + + free_donations(); free_factions(); free_units(); free_regions(); diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index 4afeac803..5f1c31743 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -232,6 +232,7 @@ void equipment_done(void) { free(eq->name); if (eq->spellbook) { spellbook_clear(eq->spellbook); + free(eq->spellbook); } // TODO: items, subsets free(eq); diff --git a/src/kernel/item.c b/src/kernel/item.c index 95d7461aa..66e361156 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -518,6 +518,11 @@ static item *icache; static int icache_size; #define ICACHE_MAX 100 +void item_done(void) { + i_freeall(&icache); + icache_size = 0; +} + void i_free(item * i) { if (icache_size >= ICACHE_MAX) { diff --git a/src/kernel/item.h b/src/kernel/item.h index fc3c2c909..c3b33070e 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -59,6 +59,8 @@ extern "C" { #define NMF_PLURAL 0x01 #define NMF_APPEARANCE 0x02 + void item_done(void); + typedef int(*rtype_uchange) (struct unit * user, const struct resource_type * rtype, int delta); typedef int(*rtype_uget) (const struct unit * user, diff --git a/src/util/attrib.c b/src/util/attrib.c index c22570356..e6392aeeb 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -412,6 +412,7 @@ void a_write_orig(struct storage *store, const attrib * attribs, const void *own WRITE_TOK(store, "end"); } -void free_attribs(void) { +void attrib_done(void) { cb_clear(&cb_deprecated); + memset(at_hash, 0, sizeof at_hash); } diff --git a/src/util/attrib.h b/src/util/attrib.h index b41ac2bcf..b9378ab55 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -81,7 +81,7 @@ extern "C" { int a_read(struct gamedata *data, attrib ** attribs, void *owner); void a_write(struct storage *store, const attrib * attribs, const void *owner); - void free_attribs(void); + void attrib_done(void); #define DEFAULT_AGE NULL #define DEFAULT_INIT NULL diff --git a/src/util/crmessage.c b/src/util/crmessage.c index d15228510..98afe0f05 100644 --- a/src/util/crmessage.c +++ b/src/util/crmessage.c @@ -32,6 +32,15 @@ typedef struct tsf_list { static tsf_list *tostringfs; +void crmessage_done(void) { + tsf_list **tsp = &tostringfs; + while (*tsp) { + tsf_list *ts = *tsp; + *tsp = ts->next; + free(ts); + } +} + static tostring_f tsf_find(const char *name) { if (name != NULL) { diff --git a/src/util/crmessage.h b/src/util/crmessage.h index be6b67367..3cd71d71c 100644 --- a/src/util/crmessage.h +++ b/src/util/crmessage.h @@ -22,6 +22,8 @@ extern "C" { struct message; struct message_type; + void crmessage_done(void); + typedef int(*tostring_f) (variant data, char *buffer, const void *userdata); void tsf_register(const char *name, tostring_f fun); /* registers a new type->string-function */ diff --git a/src/util/xml.c b/src/util/xml.c index 2d49f2a7d..644698119 100644 --- a/src/util/xml.c +++ b/src/util/xml.c @@ -89,6 +89,15 @@ typedef struct xml_reader { static xml_reader *xmlReaders; +void xml_done(void) { + xml_reader ** xrp = &xmlReaders; + while (*xrp) { + xml_reader *xr = *xrp; + *xrp = xr->next; + free(xr); + } +} + void xml_register_callback(xml_callback callback) { xml_reader *reader = (xml_reader *)malloc(sizeof(xml_reader)); diff --git a/src/util/xml.h b/src/util/xml.h index b5beee233..921cd3f53 100644 --- a/src/util/xml.h +++ b/src/util/xml.h @@ -21,13 +21,17 @@ extern "C" { /* new xml functions: */ #include - typedef int (*xml_callback) (xmlDocPtr); - extern void xml_register_callback(xml_callback callback); - extern double xml_fvalue(xmlNodePtr node, const char *name, double dflt); - extern int xml_ivalue(xmlNodePtr node, const char *name, int dflt); - extern bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt); + + typedef int (*xml_callback) (xmlDocPtr); + + void xml_register_callback(xml_callback callback); + double xml_fvalue(xmlNodePtr node, const char *name, double dflt); + int xml_ivalue(xmlNodePtr node, const char *name, int dflt); + bool xml_bvalue(xmlNodePtr node, const char *name, bool dflt); #endif - extern int read_xml(const char *filename, const char *catalog); + + void xml_done(void); + int read_xml(const char *filename, const char *catalog); #ifdef __cplusplus }