From 65bd06aae580738ea7a2ae897e12455adee6bb93 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 27 Sep 2025 18:16:23 +0200 Subject: [PATCH] fix some potential leaks --- src/g_game.c | 2 ++ src/hardware/hw_batching.c | 4 ---- src/hardware/hw_bsp.c | 12 +++++++----- src/hu_stuff.c | 6 ++---- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 0b74aca5c..b25db24d3 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3584,6 +3584,8 @@ void G_SaveGameData(boolean force) if (!FIL_CopyFile(gamedatafilename, backupfile)) { CONS_Alert(CONS_WARNING,"Failed to create a backup of save data. Will not attempt to write to save data\n"); + free(save.buffer); + save.p = save.buffer = NULL; return; } } diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 5dcbfb4cf..3e0c2320b 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -455,7 +455,6 @@ void HWR_RenderBatches(void) { GL_SetShader(nextShader); currentShader = nextShader; - changeShader = false; ps_hw_numshaders.value.i++; } @@ -465,7 +464,6 @@ void HWR_RenderBatches(void) // texture should be already ready for use from calls to GL_SetTexture during batch collection GL_SetTexture(nextTexture); currentTexture = nextTexture; - changeTexture = false; ps_hw_numtextures.value.i++; } @@ -473,7 +471,6 @@ void HWR_RenderBatches(void) if (changePolyFlags) { currentPolyFlags = nextPolyFlags; - changePolyFlags = false; ps_hw_numpolyflags.value.i++; } @@ -481,7 +478,6 @@ void HWR_RenderBatches(void) if (changeSurfaceInfo) { currentSurfaceInfo = nextSurfaceInfo; - changeSurfaceInfo = false; ps_hw_numcolors.value.i++; } diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index d2a5ac498..8cad91168 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -974,7 +974,7 @@ void HWR_CreatePlanePolygons(INT32 bspnum) CONS_Debug(DBG_RENDER, "Looking for boundaries of map...\n"); #endif M_ClearBox(rootbbox); - for (i = 0;i < numvertexes; i++) + for (i = 0; i < numvertexes; i++) M_AddToBox(rootbbox, vertexes[i].x, vertexes[i].y); #ifdef DEBUG_HWBSP @@ -985,8 +985,8 @@ void HWR_CreatePlanePolygons(INT32 bspnum) // allocate extra data for each subsector present in map totsubsectors = numsubsectors + NEWSUBSECTORS; - extrasubsectors = calloc(totsubsectors, sizeof (*extrasubsectors)); - if (UNLIKELY(extrasubsectors == NULL)) + extrasubsectors = calloc(totsubsectors, sizeof(*extrasubsectors)); + if (UNLIKELY(!extrasubsectors)) I_Error("couldn't malloc extrasubsectors totsubsectors %s\n", sizeu1(totsubsectors)); // number of the first new subsector that might be added @@ -1009,11 +1009,13 @@ void HWR_CreatePlanePolygons(INT32 bspnum) rootpv->y = FIXED_TO_FLOAT(rootbbox[BOXBOTTOM]); //ll rootpv++; - WalkBSPNode(bspnum, rootp, NULL,rootbbox); + WalkBSPNode(bspnum, rootp, NULL, rootbbox); - i = SolveTProblem(); #ifdef DEBUG_HWBSP + i = SolveTProblem(); CONS_Debug(DBG_RENDER, "%d point divides a polygon line\n",i); +#else + SolveTProblem(); #endif AdjustSegs(); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 714198e5c..2f9171a9f 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1234,8 +1234,8 @@ static void HU_SendChatMessage(void) if (len > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm { INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); const char *newmsg; + CLEANUP(pfree) char *nodenum = (char*) malloc(3); // what we're gonna do now is check if the node exists // with that logic, characters 4 and 5 are our numbers: @@ -1260,7 +1260,6 @@ static void HU_SendChatMessage(void) else { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } @@ -1270,13 +1269,11 @@ static void HU_SendChatMessage(void) if (msg[5] != ' ') { HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); return; } } target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); //CONS_Printf("%d\n", target); // check for target player, if it doesn't exist then we can't send the message! @@ -1292,6 +1289,7 @@ static void HU_SendChatMessage(void) newmsg = msg+5+spc; strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } + if (ci > 3) // don't send target+flags+empty message. { if (teamtalk)