From d32b3d5453f040519ad72fbc7aa07685c670f0df Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Fri, 16 Oct 2020 22:46:00 +0000 Subject: [PATCH] cvar: Use Mem_strdup to copy off cvar defaults when registering git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13013 d7cf8633-e32d-0410-b094-e92efae38249 --- cvar.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cvar.c b/cvar.c index 22e8f512..6bac3263 100644 --- a/cvar.c +++ b/cvar.c @@ -546,8 +546,6 @@ void Cvar_RegisterVariable (cvar_t *variable) { cvar_state_t *cvars = NULL; cvar_t *current, *cvar; - char *oldstr; - size_t alloclen; int i; switch (variable->flags & (CF_CLIENT | CF_SERVER)) @@ -622,12 +620,9 @@ void Cvar_RegisterVariable (cvar_t *variable) } // copy the value off, because future sets will Z_Free it - oldstr = (char *)variable->string; - alloclen = strlen(variable->string) + 1; - variable->string = (char *)Z_Malloc (alloclen); - memcpy ((char *)variable->string, oldstr, alloclen); - variable->defstring = (char *)Z_Malloc (alloclen); - memcpy ((char *)variable->defstring, oldstr, alloclen); + variable->name = (char *)Mem_strdup(zonemempool, variable->name); + variable->string = (char *)Mem_strdup(zonemempool, variable->string); + variable->defstring = (char *)Mem_strdup(zonemempool, variable->string); variable->value = atof (variable->string); variable->integer = (int) variable->value; variable->aliasindex = 0; -- 2.39.2