From 1bcff874c52aca3134cee636178ab5d6272fef58 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 26 Apr 2015 18:55:43 -0400 Subject: Don't read currentthinker->next after Z_Free(). Save the next pointer in the P_RunThinkers() loop when iterating through thinkers, so that if the current thinker is freed we can still advance to the next thinker without dereferencing freed memory. --- src/heretic/p_tick.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/heretic') diff --git a/src/heretic/p_tick.c b/src/heretic/p_tick.c index c93a211f..323cc1e6 100644 --- a/src/heretic/p_tick.c +++ b/src/heretic/p_tick.c @@ -110,11 +110,13 @@ void P_AllocateThinker(thinker_t * thinker) void P_RunThinkers(void) { - thinker_t *currentthinker; + thinker_t *currentthinker, *nextthinker; currentthinker = thinkercap.next; while (currentthinker != &thinkercap) { + nextthinker = currentthinker->next; + if (currentthinker->function == (think_t) - 1) { // time to remove it currentthinker->next->prev = currentthinker->prev; @@ -126,7 +128,7 @@ void P_RunThinkers(void) if (currentthinker->function) currentthinker->function(currentthinker); } - currentthinker = currentthinker->next; + currentthinker = nextthinker; } } -- cgit v1.2.3