]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Fix memory corruption in loadconfig while in game/menu.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 4 Mar 2015 14:59:32 +0000 (14:59 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Wed, 4 Mar 2015 15:04:43 +0000 (16:04 +0100)
Autocvars are engine strings to QC, so we can't just let them die.
Instead, reset them to default, which is what the progs would expect
anyway.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12182 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=b0ad0294366f5d21928cee69b98a43f4aa12962b

cvar.c

diff --git a/cvar.c b/cvar.c
index e92e0dfa3ac7b9b3e31ff5f27cbc72cdbcc7b6c8..5ae8e521c53b6daf2231ceda3732606b1edbdecc 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -262,6 +262,20 @@ void Cvar_CompleteCvarPrint (const char *partial)
                        Con_Printf ("^3%s^7 is \"%s\" [\"%s\"] %s\n", cvar->name, cvar->string, cvar->defstring, cvar->description);
 }
 
+// check if a cvar is held by some progs
+static qboolean Cvar_IsAutoCvar(cvar_t *var)
+{
+       int i;
+       prvm_prog_t *prog;
+       for (i = 0;i < PRVM_PROG_MAX;i++)
+       {
+               prog = &prvm_prog_list[i];
+               if (prog->loaded && var->globaldefindex_progid[i] == prog->id)
+                       return true;
+       }
+       return false;
+}
+
 // we assume that prog is already set to the target progs
 static void Cvar_UpdateAutoCvar(cvar_t *var)
 {
@@ -751,6 +765,18 @@ void Cvar_RestoreInitState(void)
                        if (!(c->flags & CVAR_ALLOCATED))
                        {
                                Con_DPrintf("Cvar_RestoreInitState: Unable to destroy cvar \"%s\", it was registered after init!\n", c->name);
+                               // In this case, at least reset it to the default.
+                               if((c->flags & CVAR_NORESETTODEFAULTS) == 0)
+                                       Cvar_SetQuick(c, c->defstring);
+                               cp = &c->next;
+                               continue;
+                       }
+                       if (Cvar_IsAutoCvar(c))
+                       {
+                               Con_DPrintf("Cvar_RestoreInitState: Unable to destroy cvar \"%s\", it is an autocvar used by running progs!\n", c->name);
+                               // In this case, at least reset it to the default.
+                               if((c->flags & CVAR_NORESETTODEFAULTS) == 0)
+                                       Cvar_SetQuick(c, c->defstring);
                                cp = &c->next;
                                continue;
                        }