From 33145ab2ae45737c517cb65149bc4d91106a97e3 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 14 Feb 2023 02:48:09 -0800 Subject: [PATCH] p_mobj.c: reference count kitemcap and overlaycap With the old code, if the object at the head of the list was removed, it would leave the reference behind, extending the lifetime of the thinker until P_RunKartItems or P_RunOverlays was run. --- src/p_mobj.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index b773134b9..07e6d10d6 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -5280,13 +5280,13 @@ void P_AddKartItem(mobj_t *thing) // Keeps the hnext list from corrupting. static void P_RemoveKartItem(mobj_t *thing) { - mobj_t *mo; - for (mo = kitemcap; mo; mo = mo->itnext) + mobj_t *mo, **p; + for (mo = *(p = &kitemcap); mo; mo = *(p = &mo->itnext)) { - if (mo->itnext != thing) + if (mo != thing) continue; - P_SetTarget(&mo->itnext, thing->itnext); + P_SetTarget(p, thing->itnext); P_SetTarget(&thing->itnext, NULL); return; } @@ -5433,13 +5433,13 @@ static void P_AddOverlay(mobj_t *thing) // Keeps the hnext list from corrupting. static void P_RemoveOverlay(mobj_t *thing) { - mobj_t *mo; - for (mo = overlaycap; mo; mo = mo->hnext) + mobj_t *mo, **p; + for (mo = *(p = &overlaycap); mo; mo = *(p = &mo->hnext)) { - if (mo->hnext != thing) + if (mo != thing) continue; - P_SetTarget(&mo->hnext, thing->hnext); + P_SetTarget(p, thing->hnext); P_SetTarget(&thing->hnext, NULL); return; }