From: cloudwalk Date: Fri, 24 Jul 2020 16:13:08 +0000 (+0000) Subject: ent_create: Fix potential memory leaks. Misc improvements X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=31cd12ca04bc7aab4d3abd29184b2d76a3ebbe2c ent_create: Fix potential memory leaks. Misc improvements git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12876 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/prvm_edict.c b/prvm_edict.c index 6470767e..92004b0a 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -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; } diff --git a/sv_ccmds.c b/sv_ccmds.c index c4aad6fc..f6d71256 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -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; }