]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
ent_create: Fix potential memory leaks. Misc improvements
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 24 Jul 2020 16:13:08 +0000 (16:13 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 24 Jul 2020 16:13:08 +0000 (16:13 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12876 d7cf8633-e32d-0410-b094-e92efae38249

prvm_edict.c
sv_ccmds.c

index 6470767ed720ac04b5ed5faeaf8fc12b3a7fbb7f..92004b0ae37104c4a7b29556b7f131d671f082dc 100644 (file)
@@ -1449,6 +1449,7 @@ qboolean PRVM_ED_CallSpawnFunction(prvm_prog_t *prog, prvm_edict_t *ent, const c
                }
                return true;
        }
+       PRVM_ED_Free(prog, ent);
        return false;
 }
 
index c4aad6fc2457312d06fb4963ccdaa6b6e377fc4a..f6d71256aa6a6c898c9a538cd75db12e2442bedc 100644 (file)
@@ -1519,13 +1519,15 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
 
        PRVM_ED_ParseEpair(prog, ed, PRVM_ED_FindField(prog, "classname"), Cmd_Argv(cmd, 1), false);
 
+       // Allow more than one key/value pair by cycling between expecting either one.
        for(i = 2; i < Cmd_Argc(cmd); i++)
        {
                if(!expectval)
                {
                        if(!(key = PRVM_ED_FindField(prog, Cmd_Argv(cmd, i))))
                        {
-                               Con_Printf("Key %s not found!\n", Cmd_Argv(cmd, i));
+                               print("Key %s not found!\n", Cmd_Argv(cmd, i));
+                               PRVM_ED_Free(prog, ed);
                                return;
                        }
 
@@ -1540,12 +1542,13 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
                        expectval = false;
                }
        }
-       
+
        if(!haveorigin)
        {
                print("Missing origin\n");
                if(cmd->source == src_client)
                        print("This should never happen if you're a player. Please report this to a developer.\n");
+               PRVM_ED_Free(prog, ed);
                return;
        }
 
@@ -1557,6 +1560,7 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
                print("Could not spawn a \"%s\". No such entity or it has no spawn function\n", Cmd_Argv(cmd, 1));
                if(cmd->source == src_client)
                        Con_Printf("%s tried to spawn a \"%s\"\n", host_client->name, Cmd_Argv(cmd, 1));
+               // CallSpawnFunction already freed the edict for us.
                return;
        }