From dda845e2f454a0dcdb39898373cf4ce7008519e2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 7 Sep 2016 20:46:41 +0200 Subject: [PATCH] free configuration data (valgrind calls it still-reachable leaks). --- src/eressea.c | 19 +++++++++++++------ src/kernel/config.c | 9 ++++----- src/kernel/equipment.c | 2 +- src/kernel/equipment.h | 3 ++- src/report.c | 7 ------- src/reports.c | 9 +++++++++ src/reports.h | 4 ++-- src/util/message.c | 11 ++++++++++- src/util/message.h | 4 +++- 9 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/eressea.c b/src/eressea.c index 18c98cad6..7dff11574 100755 --- a/src/eressea.c +++ b/src/eressea.c @@ -14,23 +14,27 @@ #include #include #include -#include -#include -#include #include +#include +#include +#include +#include #include #include #include #include +#include #include + #include "chaos.h" -#include "report.h" -#include "items.h" #include "creport.h" +#include "items.h" #include "jsreport.h" #include "names.h" -#include "wormhole.h" +#include "report.h" +#include "reports.h" #include "spells.h" +#include "wormhole.h" void game_done(void) { @@ -51,6 +55,9 @@ 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 7fae8df23..e45ffdde9 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1080,7 +1080,6 @@ void free_gamedata(void) { int i; free_donations(); - free_equipment(); for (i = 0; i != MAXLOCALES; ++i) { if (defaults[i]) { @@ -1094,15 +1093,15 @@ void free_gamedata(void) free_borders(); free_alliances(); + while (global.attribs) { + a_remove(&global.attribs, global.attribs); + } + while (planes) { plane *pl = planes; planes = planes->next; free_plane(pl); } - - while (global.attribs) { - a_remove(&global.attribs, global.attribs); - } } const char * game_name(void) { diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index f5bd2fd29..15db54b32 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -224,7 +224,7 @@ void equip_items(struct item **items, const struct equipment *eq) } } -void free_equipment(void) { +void equipment_done(void) { equipment **eqp = &equipment_sets; while (*eqp) { equipment *eq = *eqp; diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index 1ce454111..11511d99a 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -54,6 +54,8 @@ extern "C" { void(*callback) (const struct equipment *, struct unit *); } equipment; + void equipment_done(void); + struct equipment *create_equipment(const char *eqname); struct equipment *get_equipment(const char *eqname); @@ -75,7 +77,6 @@ extern "C" { int mask); void equip_items(struct item **items, const struct equipment *eq); - void free_equipment(void); #ifdef __cplusplus } #endif diff --git a/src/report.c b/src/report.c index 6436fe990..294f0c7f5 100644 --- a/src/report.c +++ b/src/report.c @@ -2547,13 +2547,6 @@ static void update_find(void) initial = false; } -bool kann_finden(faction * f1, faction * f2) -{ - update_find(); - return (bool)(can_find(f1, f2) != NULL); -} - -/******* end summary ******/ void register_nr(void) { diff --git a/src/reports.c b/src/reports.c index 74ba8656a..06408d96e 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1094,6 +1094,15 @@ void register_reporttype(const char *extension, report_fun write, int flag) report_types = type; } +void reports_done(void) { + report_type **rtp = &report_types; + while (*rtp) { + report_type *rt = *rtp; + *rtp = rt->next; + free(rt); + } +} + static quicklist *get_regions_distance(region * root, int radius) { quicklist *ql, *rlist = NULL; diff --git a/src/reports.h b/src/reports.h index be99fbba7..584fe7d4a 100644 --- a/src/reports.h +++ b/src/reports.h @@ -44,8 +44,8 @@ extern "C" { extern bool noreports; extern const char *visibility[]; - /* kann_finden speedups */ - bool kann_finden(struct faction *f1, struct faction *f2); + void reports_done(void); + struct unit *can_find(struct faction *, struct faction *); /* funktionen zum schreiben eines reports */ diff --git a/src/util/message.c b/src/util/message.c index 92a5b43e6..f19fc3313 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -32,7 +32,7 @@ const char *mt_name(const message_type * mtype) return mtype->name; } -arg_type *argtypes = NULL; +static arg_type *argtypes = NULL; void register_argtype(const char *name, void(*free_arg) (variant), @@ -246,3 +246,12 @@ struct message *msg_addref(struct message *msg) ++msg->refcount; return msg; } + +void message_done(void) { + arg_type **atp = &argtypes; + while (*atp) { + arg_type *at = *atp; + *atp = at->next; + free(at); + } +} diff --git a/src/util/message.h b/src/util/message.h index 687413605..5937fb83e 100644 --- a/src/util/message.h +++ b/src/util/message.h @@ -40,8 +40,10 @@ extern "C" { int refcount; } message; + void message_done(void); + void mt_clear(void); - struct message_type *mt_new(const char *name, const char **args); + struct message_type *mt_new(const char *name, const char *args[]); struct message_type *mt_new_va(const char *name, ...); /* mt_new("simple_sentence", "subject:string", "predicate:string", * "object:string", "lang:locale", NULL); */