summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2016-12-11 16:43:48 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2016-12-11 16:43:48 +0000
commit4ad375c3b0e3f65416c02ca7b126b2e7fe375db1 (patch)
tree262bd7617cd35c041727459e3e3f34cb36fbd863
parentba0895121b44b21d351ee69a07613f524f322617 (diff)
downloadnetsurf-4ad375c3b0e3f65416c02ca7b126b2e7fe375db1.tar.gz
netsurf-4ad375c3b0e3f65416c02ca7b126b2e7fe375db1.tar.bz2
Ensure memory used by Messages is freed on exit
-rw-r--r--desktop/netsurf.c3
-rw-r--r--utils/messages.c25
-rw-r--r--utils/messages.h8
3 files changed, 36 insertions, 0 deletions
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