From e57427142b42dda3be42082237ced73c5d685e79 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 4 Mar 2023 00:38:32 +0900 Subject: [PATCH] [util] Clean up some memory leaks in cmd --- libs/util/cmd.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/util/cmd.c b/libs/util/cmd.c index 4b33673e4..6997b407d 100644 --- a/libs/util/cmd.c +++ b/libs/util/cmd.c @@ -310,6 +310,13 @@ Cmd_CompleteBuildList (const char *partial) } /* Hash table functions for aliases and commands */ +static void +cmd_free (void *_c, void *unused) +{ + cmd_function_t *cmd = _c; + free (cmd); +} + static void cmd_alias_free (void *_a, void *unused) { @@ -606,10 +613,20 @@ Cmd_StuffCmds_f (void) Cmd_StuffCmds (cbuf_active); } +static void +cmd_shutdown (void *data) +{ + Cbuf_Delete (cmd_cbuf); + Hash_DelTable (cmd_hash); + Hash_DelTable (cmd_alias_hash); + Hash_DelTable (cmd_provider_hash); +} + VISIBLE void Cmd_Init_Hash (void) { - cmd_hash = Hash_NewTable (1021, cmd_get_key, 0, 0, 0); + Sys_RegisterShutdown (cmd_shutdown, 0); + cmd_hash = Hash_NewTable (1021, cmd_get_key, cmd_free, 0, 0); cmd_alias_hash = Hash_NewTable (1021, cmd_alias_get_key, cmd_alias_free, 0, 0); cmd_provider_hash = Hash_NewTable(1021, cmd_provider_get_key,