From 4ad375c3b0e3f65416c02ca7b126b2e7fe375db1 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sun, 11 Dec 2016 16:43:48 +0000 Subject: Ensure memory used by Messages is freed on exit --- desktop/netsurf.c | 3 +++ utils/messages.c | 25 +++++++++++++++++++++++++ utils/messages.h | 8 ++++++++ 3 files changed, 36 insertions(+) diff --git a/desktop/netsurf.c b/desktop/netsurf.c index d129ef72f..4a1473753 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -279,6 +279,9 @@ void netsurf_exit(void) LOG("Destroying System colours"); ns_system_colour_finalize(); + LOG("Destroying Messages"); + messages_destroy(); + corestrings_fini(); LOG("Remaining lwc strings:"); lwc_iterate_strings(netsurf_lwc_iterator, NULL); diff --git a/utils/messages.c b/utils/messages.c index e69a85524..0c558cdfc 100644 --- a/utils/messages.c +++ b/utils/messages.c @@ -177,6 +177,22 @@ messages_get_ctx(const char *key, struct hash_table *ctx) return r; } + +/** + * Free memory used by a messages hash. + * The context will not be valid after this function returns. + * + * \param ctx context of messages file to free + */ +static void messages_destroy_ctx(struct hash_table *ctx) +{ + if (ctx == NULL) + return; + + hash_destroy(ctx); +} + + /* exported interface documented in messages.h */ nserror messages_add_from_file(const char *path) { @@ -390,3 +406,12 @@ const char *messages_get_errorcode(nserror code) /* Unknown error */ return messages_get_ctx("Unknown", messages_hash); } + + +/* exported function documented in utils/messages.h */ +void messages_destroy(void) +{ + messages_destroy_ctx(messages_hash); + messages_hash = NULL; +} + diff --git a/utils/messages.h b/utils/messages.h index 784e5fe6a..d4be893af 100644 --- a/utils/messages.h +++ b/utils/messages.h @@ -90,4 +90,12 @@ const char *messages_get_errorcode(nserror code); char *messages_get_buff(const char *key, ...); +/** + * Free memory used by the standard Messages hash + * + * \param code errorcode of message + * \return message text + */ +void messages_destroy(void); + #endif -- cgit v1.2.3