From 3bdc745bd15f5742c41f560c5f7c397bc5ca8a7a 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 1/8] Fix use-after-free when mobj is removed while still playing sounds --- src/p_setup.c | 2 ++ src/s_sound.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/p_setup.c b/src/p_setup.c index b7b8f03d5..2993bb5d2 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 5bc830252..651d579b8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -772,9 +772,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; From 3f2e0bd3495ed3828ff9beae5967c8bdddb5bb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Sat, 6 Dec 2025 15:37:02 +0100 Subject: [PATCH 2/8] Fix memory leak in AATree string trees --- src/m_aatree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/m_aatree.c b/src/m_aatree.c index f78355eaf..7fb847aab 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -49,17 +49,19 @@ aatree_t *M_AATreeAlloc(UINT32 flags) return aatree; } -static void M_AATreeFree_Node(aatree_node_t *node) +static void M_AATreeFree_Node(aatree_node_t *node, bool is_string) { - if (node->left) M_AATreeFree_Node(node->left); - if (node->right) M_AATreeFree_Node(node->right); + if (node->left) M_AATreeFree_Node(node->left, is_string); + if (node->right) M_AATreeFree_Node(node->right, is_string); + if (is_string) + Z_Free(node->value); Z_Free(node); } void M_AATreeFree(aatree_t *aatree) { if (aatree->root) - M_AATreeFree_Node(aatree->root); + M_AATreeFree_Node(aatree->root, (aatree->flags & AATREE_STRING) == AATREE_STRING); Z_Free(aatree); } From a191c8b71ebc2c73794a586423684d6c94e78b29 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 19:03:26 +0100 Subject: [PATCH 3/8] g_demo: screw you LF2_EXISTSHACK --- src/g_demo.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/g_demo.c b/src/g_demo.c index f828d0343..4c3219368 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2795,7 +2795,7 @@ void G_DoPlayDemo(char *defdemoname) demobuf.p += 4; // Extrainfo location // ...*map* not loaded? - if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1]) { snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -2836,6 +2836,16 @@ void G_DoPlayDemo(char *defdemoname) return; } + // ...*map* not loaded? + if (!(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + { + snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); + G_ResetDemoPlayback(); + return; + } + // Set color for (i = 0; i < MAXSKINCOLORS; i++) { From ed758fc9217361a6904158800646c70d7041fa6f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 20:23:47 +0100 Subject: [PATCH 4/8] g_demo: check for maplump existance directly cant really rely on mapheaderinfo to tell us if some map exists or not --- src/g_demo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/g_demo.c b/src/g_demo.c index 4c3219368..a714f8e48 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2795,7 +2795,7 @@ void G_DoPlayDemo(char *defdemoname) demobuf.p += 4; // Extrainfo location // ...*map* not loaded? - if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1]) + if (!gamemap || (gamemap > NUMMAPS) || (W_CheckNumForName(G_BuildMapName(gamemap)) == LUMPERROR)) { snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -2837,7 +2837,7 @@ void G_DoPlayDemo(char *defdemoname) } // ...*map* not loaded? - if (!(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) { snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); From 3cb4e86b480000bdfab1f75c46e2c63b1c0452f5 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 19:51:29 +0100 Subject: [PATCH 5/8] i_system: "fix" recursive i_quit well this still aint working all to great, but atleast this allows me to quit the game if it gets stuck without having to always send a kill signal to it copy pasted from what the dedicated build does --- src/sdl/i_system.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 00250bf4f..8cb67c9d6 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1851,17 +1851,20 @@ INT32 I_StartupSystem(void) return 0; } +boolean is_quitting = false; + // // I_Quit // FUNCNORETURN void ATTRNORETURN I_Quit(void) { - static SDL_bool quiting = SDL_FALSE; - /* prevent recursive I_Quit() */ - if (quiting) goto death; + if (is_quitting) + abort(); + + is_quitting = true; SDL_ShowCursor(SDL_TRUE); - quiting = SDL_FALSE; + I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. D_SaveBan(); // save the ban list @@ -1888,7 +1891,7 @@ FUNCNORETURN void ATTRNORETURN I_Quit(void) } if (myargmalloc) free(myargv); // Deallocate allocated memory -death: + W_Shutdown(); exit(0); } From a2feaa7fde4c2d3138cf21c40c2f8f671fac78ad Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 20:22:25 +0100 Subject: [PATCH 6/8] dont call I_Quit from within "quit_handler", let it signal main loop to quit fixes an issue for me which led to having the game threads getting stuck when sending an interrupt signal to the game due to some thread issues with the sdl subsystems shoutout to dsda doom for this --- src/d_main.c | 3 +++ src/dedicated/i_system.c | 12 ++++++++++-- src/i_system.h | 3 ++- src/sdl/i_system.cpp | 22 ++++++++++------------ src/sdl/i_video.c | 3 ++- src/sdl/mixer_sound.c | 3 ++- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c46ef0c44..ab10af215 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,6 +679,9 @@ void D_SRB2Loop(void) for (;;) { + if (I_Interrupted()) + I_Quit(); + // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 31eaf0346..5edb71a99 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,11 +1075,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +static volatile sig_atomic_t interrupted = 0; + +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } #ifdef HAVE_LIBBACKTRACE diff --git a/src/i_system.h b/src/i_system.h index 7084c655f..68d51f022 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,7 +29,6 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 - /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -191,6 +190,8 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); +boolean I_Interrupted(void); + /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 8cb67c9d6..60e5108ac 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,21 +1670,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ -#ifdef HAVE_THREADS - if (g_main_thread_id != std::this_thread::get_id()) - { - // Do not attempt any sort of recovery if this signal triggers off the main thread - signal(num, SIG_DFL); - raise(num); - exit(-2); - } -#endif +static volatile sig_atomic_t interrupted = 0; +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) +{ signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } static void I_RegisterSignals(void) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index c2d87e3f1..ae2691359 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2012,7 +2012,8 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - SDL_QuitSubSystem(SDL_INIT_VIDEO); + if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 529b47399..c455aab01 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,7 +237,8 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - SDL_QuitSubSystem(SDL_INIT_AUDIO); + if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme) From c19c80d79744671e5984364ecbb027f3d7d55448 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 7 Dec 2025 20:40:30 +0100 Subject: [PATCH 7/8] command.c: fix "alias" command crashing when no aliases were registered if we dont have aliases list how do we check the next alias in the list aswell? --- src/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command.c b/src/command.c index 0cf1c85ff..7e0c34d03 100644 --- a/src/command.c +++ b/src/command.c @@ -652,7 +652,7 @@ static void COM_Alias_f(void) CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); int count = 0; - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { if (strncmp(begin, head->name, szBegin) == 0) { @@ -673,7 +673,7 @@ static void COM_Alias_f(void) /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { CONS_Printf(alias_format, head->name, head->value); } From eb4d9bbdd531710b51d90e2ec5aed610a4931ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Mon, 8 Dec 2025 21:14:54 +0100 Subject: [PATCH 8/8] Fix decompression warning when starting a server --- src/d_clisrv.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index fa1536e72..8f2cc5afb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1775,6 +1775,9 @@ static void SV_SendPlayerInfo(INT32 node) static void SV_SendMapIcon(INT32 node) { + if (node == 0) + return; + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); const char *map = va("%sP", G_BuildMapName(gamemap));