From 9f71d552581e553bb0254cc2758873b44bffe683 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 27 Aug 2017 01:00:57 +0100 Subject: [PATCH] fixing couple of small memory leaks --- src/common/cvar.c | 21 +++++++++++++++++++++ src/common/header/common.h | 2 ++ src/common/misc.c | 1 + 3 files changed, 24 insertions(+) diff --git a/src/common/cvar.c b/src/common/cvar.c index 2f59bf46..c972f4bc 100644 --- a/src/common/cvar.c +++ b/src/common/cvar.c @@ -585,3 +585,24 @@ Cvar_Init(void) Cmd_AddCommand("cvarlist", Cvar_List_f); } +/* + * Free list of cvars + */ +void +Cvar_Fini(void) +{ + cvar_t *var; + + for (var = cvar_vars; var;) + { + cvar_t *c = var; + Z_Free(var->string); + Z_Free(var->name); + Z_Free(var); + var = c->next; + } + + Cmd_RemoveCommand("cvarlist"); + Cmd_RemoveCommand("set"); +} + diff --git a/src/common/header/common.h b/src/common/header/common.h index 7e329180..42503051 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -475,6 +475,8 @@ void Cvar_WriteVariables(char *path); void Cvar_Init(void); +void Cvar_Fini(void); + char *Cvar_Userinfo(void); /* returns an info string containing all the CVAR_USERINFO cvars */ diff --git a/src/common/misc.c b/src/common/misc.c index 4cc2adb4..91b3a148 100644 --- a/src/common/misc.c +++ b/src/common/misc.c @@ -411,5 +411,6 @@ Qcommon_Frame(int msec) void Qcommon_Shutdown(void) { + Cvar_Fini(); }