From 82b774b2c3ccb29056fbefad9def39e6bbd07c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 6 Dec 2025 14:05:06 +0100 Subject: [PATCH] Fix use-after-free when mobj is removed while still playing sounds --- src/p_setup.c | 2 ++ src/s_sound.c | 7 ++++++- src/sdl/sdl_sound.c | 2 -- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index a04751ac9..618acff5e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -812,6 +812,8 @@ static void P_LoadSectors(UINT8 *data) ss->tag = SHORT(ms->tag); ss->flags |= SF_FLIPSPECIAL_FLOOR; + + ss->soundorg.thinker.function = (actionf_p1)P_MobjThinker; } // set the sky flat num diff --git a/src/s_sound.c b/src/s_sound.c index 67a00888d..9c34918f5 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -771,9 +771,14 @@ void S_UpdateSounds(void) volume = c->volume; // 8 bits internal volume precision sep = NORM_SEP; + if (P_MobjWasRemoved(c->origin)) + { + // origin was removed, stop the music + S_StopChannel(cnum); + } // check non-local sounds for distance clipping // or modify their params - if (c->origin) + else { boolean itsUs = false; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index d3736438c..3a259875f 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1001,7 +1001,6 @@ INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, /*UINT8 pitch, UINT8 prio { //(void)channel; // ignore this - we do mixing ourselves so we don't need it //(void)priority; // priority and channel management is handled by SRB2... - //(void)pitch; // TODO (we can do this now with SDL3) if (S_sfx[id].data == NULL) return -1; @@ -1074,7 +1073,6 @@ boolean I_SoundIsPlaying(INT32 handle) void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep/*, UINT8 pitch*/) { - //(void)pitch; // TODO if (handle == -1) return;