Skip to content

Commit

Permalink
Fix potential crash after loading of saved game (#242, #266)
Browse files Browse the repository at this point in the history
When number of edicts parsed from saved game is smaller than `sv.num_edicts`, "old" edicts are not freed nor unlinked while their memory can be reused by newly spawned entities

(adapted from sezero#75)
  • Loading branch information
alexey-lysiuk authored and andrei-drexler committed Nov 18, 2023
1 parent 42850da commit 67e230e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2653,6 +2653,10 @@ static void Host_Loadgame_f (void)
entnum++;
}

// Free edicts allocated during map loading but no longer used after restoring saved game state
for (i = entnum; i < qcvm->num_edicts; i++)
ED_Free (EDICT_NUM (i));

qcvm->num_edicts = entnum;
qcvm->time = time;
sv.autosave.time = time;
Expand Down

0 comments on commit 67e230e

Please sign in to comment.