From c482335df26a99fdd4fa4afd3f8699b4977ecc5b Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Feb 2026 21:49:49 +0100 Subject: [PATCH] delet all the Z_Free checks Z_Free already checks its input internally! --- src/f_finale.c | 4 +--- src/filesrch.c | 14 ++++++-------- src/g_game.c | 7 ++----- src/hu_stuff.c | 12 ++++-------- src/i_tcp.c | 14 ++++---------- src/k_stats.c | 3 +-- src/lua_hudlib_drawlist.c | 15 +++------------ src/m_anigif.c | 9 +++------ src/m_cond.c | 9 +++------ src/m_menu.c | 13 +++++++++---- src/p_setup.c | 4 +--- src/p_spec.c | 3 +-- src/r_data.c | 3 +-- src/r_main.cpp | 16 ++++++---------- src/r_patch.cpp | 6 ++---- src/r_things.cpp | 2 +- src/v_video.c | 4 +--- src/w_wad.cpp | 7 +++---- src/z_zone.h | 2 +- 19 files changed, 53 insertions(+), 94 deletions(-) diff --git a/src/f_finale.c b/src/f_finale.c index 32ed8c3ec..f7efbbced 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1172,9 +1172,7 @@ void F_StartWaitingPlayers(void) randskin = M_RandomKey(numskins); boolean waithires = skins[randskin].flags && SF_HIRES; - if (waitcolormap) - Z_Free(waitcolormap); - + Z_Free(waitcolormap); waitcolormap = R_GetTranslationColormap(randskin, skins[randskin].prefcolor, 0); if (waithires) diff --git a/src/filesrch.c b/src/filesrch.c index e34b51c47..0ba117a1e 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -317,8 +317,7 @@ void closefilemenu(boolean validsize) coredirmenu = NULL; } - if (refreshdirname) - Z_Free(refreshdirname); + Z_Free(refreshdirname); refreshdirname = NULL; } @@ -346,8 +345,7 @@ void searchfilemenu(char *tempname) if (!menusearch.length) { - if (dirmenu) - Z_Free(dirmenu); + Z_Free(dirmenu); dirmenu = coredirmenu; sizedirmenu = sizecoredirmenu; @@ -389,8 +387,8 @@ void searchfilemenu(char *tempname) I_Error("searchfilemenu(): could not create \"No results...\"."); sizedirmenu = 1; dir_on[menudepthleft] = 0; - if (tempname) - Z_Free(tempname); + Z_Free(tempname); + return; } @@ -505,8 +503,8 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) { closedir(dirhandle); closefilemenu(false); - if (tempname) - Z_Free(tempname); + Z_Free(tempname); + return false; } diff --git a/src/g_game.c b/src/g_game.c index ce38ac5e1..d8a3698c4 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -521,11 +521,8 @@ void G_ClearRecords(void) INT16 i; for (i = 0; i < NUMMAPS; ++i) { - if (mainrecords[i]) - { - Z_Free(mainrecords[i]); - mainrecords[i] = NULL; - } + Z_Free(mainrecords[i]); + mainrecords[i] = NULL; } } diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 3d09971cb..e9aaac430 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1072,8 +1072,7 @@ static void Got_Saycmd(const UINT8 **p, INT32 playernum) HU_AddChatText(va(fmt2, prefix, cstart, dispname, textcolor, msg), cv_chatnotifications.value); // add to chat - if (tempchar) - Z_Free(tempchar); + Z_Free(tempchar); } #ifdef _DEBUG // I just want to point out while I'm here that because the data is still @@ -1565,8 +1564,7 @@ static void HU_drawMiniChat(void) dy = 0; dx = 0; msglines += linescount+1; - if (msg) - Z_Free(msg); + Z_Free(msg); } y = chaty - charheight*(msglines+1); @@ -1651,8 +1649,7 @@ static void HU_drawMiniChat(void) } dy += charheight; dx = 0; - if (msg) - Z_Free(msg); + Z_Free(msg); } // decrement addy and make that shit smooth: @@ -1760,8 +1757,7 @@ static void HU_drawChatLog(INT32 offset) } dy += charheight; dx = 0; - if (msg) - Z_Free(msg); + Z_Free(msg); } if (((chat_scroll >= chat_maxscroll) || (chat_scrollmedown)) && !(justscrolleddown || justscrolledup || chat_scrolltime)) // was already at the bottom of the page before new maxscroll calculation and was NOT scrolling. diff --git a/src/i_tcp.c b/src/i_tcp.c index 77cb940fd..9723d5b2d 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1512,11 +1512,8 @@ static boolean SOCK_SetBanUsername(const char *username) username = "Direct IP ban"; } - if (banned[numbans - 1].username) - { - Z_Free(banned[numbans - 1].username); - banned[numbans - 1].username = NULL; - } + Z_Free(banned[numbans - 1].username); + banned[numbans - 1].username = NULL; banned[numbans - 1].username = Z_StrDup(username); @@ -1530,11 +1527,8 @@ static boolean SOCK_SetBanReason(const char *reason) reason = "No reason given"; } - if (banned[numbans - 1].reason) - { - Z_Free(banned[numbans - 1].reason); - banned[numbans - 1].reason = NULL; - } + Z_Free(banned[numbans - 1].reason); + banned[numbans - 1].reason = NULL; banned[numbans - 1].reason = Z_StrDup(reason); diff --git a/src/k_stats.c b/src/k_stats.c index f4fac90d3..5675462fd 100644 --- a/src/k_stats.c +++ b/src/k_stats.c @@ -99,8 +99,7 @@ void K_EraseStats(void) // The only field we want to remember boolean vanilla = kartstats.vanilla; - if (kartstats.copy) - Z_Free(kartstats.copy); + Z_Free(kartstats.copy); memset(&kartstats, 0, sizeof(kartstats_t)); diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index f267c5fe3..6d3542c48 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -136,18 +136,9 @@ void LUA_HUD_DestroyDrawList(huddrawlist_h list) { if (list == NULL) return; - if (list->items) - { - Z_Free(list->items); - } - if (list->olditems) - { - Z_Free(list->olditems); - } - if (list->strbuf) - { - Z_Free(list->strbuf); - } + Z_Free(list->items); + Z_Free(list->olditems); + Z_Free(list->strbuf); Z_Free(list); } diff --git a/src/m_anigif.c b/src/m_anigif.c index a8cc21bcf..cd37b08d6 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -695,16 +695,13 @@ INT32 GIF_close(void) fclose(gif_out); gif_out = NULL; - if (gifbwr_buf) - Z_Free(gifbwr_buf); + Z_Free(gifbwr_buf); gifbwr_buf = gifbwr_cur = NULL; - if (gifframe_data) - Z_Free(gifframe_data); + Z_Free(gifframe_data); gifframe_data = NULL; - if (giflzw_hashTable) - Z_Free(giflzw_hashTable); + Z_Free(giflzw_hashTable); giflzw_hashTable = NULL; Z_Free(scrbuf_screens); diff --git a/src/m_cond.c b/src/m_cond.c index 126d5a49a..c22c966f3 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -248,12 +248,9 @@ void M_AddRawCondition(UINT8 set, UINT8 id, conditiontype_t c, INT32 r, INT16 x1 void M_ClearConditionSet(UINT8 set) { - if (conditionSets[set - 1].numconditions) - { - Z_Free(conditionSets[set - 1].condition); - conditionSets[set - 1].condition = NULL; - conditionSets[set - 1].numconditions = 0; - } + Z_Free(conditionSets[set - 1].condition); + conditionSets[set - 1].condition = NULL; + conditionSets[set - 1].numconditions = 0; conditionSets[set - 1].achieved = false; } diff --git a/src/m_menu.c b/src/m_menu.c index e720c41ad..f330503cc 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6570,17 +6570,22 @@ static void M_EraseGuest(INT32 choice) static void M_OverwriteGuest(const char *which) { - char *rguest = Z_StrDup(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-guest.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value))); + char *rguest; UINT8 *buf; size_t len; len = FIL_ReadFile(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-%s-%s.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value), cv_chooseskin.string, which), &buf); - if (!len) { + + if (!len) return; - } - if (FIL_FileExists(rguest)) { + + rguest = Z_StrDup(va("%s"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s-guest.lmp", srb2home, timeattackfolder, G_BuildMapName(cv_nextmap.value))); + + if (FIL_FileExists(rguest)) + { M_StopMessage(0); remove(rguest); } + FIL_WriteFile(rguest, buf, len); Z_Free(rguest); diff --git a/src/p_setup.c b/src/p_setup.c index d3092fa37..4e39408ea 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -320,9 +320,7 @@ void P_AddGradesForMare(INT16 i, UINT8 mare, char *gtext) */ void P_DeleteGrades(INT16 i) { - if (mapheaderinfo[i]->grades) - Z_Free(mapheaderinfo[i]->grades); - + Z_Free(mapheaderinfo[i]->grades); mapheaderinfo[i]->grades = NULL; mapheaderinfo[i]->numGradedMares = 0; } diff --git a/src/p_spec.c b/src/p_spec.c index c09daf9c1..3c6fad0c9 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -6222,8 +6222,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate) // Allocate each list for (i = 0; i < numsectors; i++) - if(secthinkers[i].thinkers) - Z_Free(secthinkers[i].thinkers); + Z_Free(secthinkers[i].thinkers); Z_Free(secthinkers); diff --git a/src/r_data.c b/src/r_data.c index 386f0e700..911413bb4 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1720,8 +1720,7 @@ void R_InitData(void) void R_ClearTextureNumCache(boolean btell) { - if (tidcache) - Z_Free(tidcache); + Z_Free(tidcache); tidcache = NULL; if (btell) CONS_Debug(DBG_SETUP, "Fun Fact: There are %d textures used in this map.\n", tidcachelen); diff --git a/src/r_main.cpp b/src/r_main.cpp index 675414bcd..e9a3317c4 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -925,11 +925,11 @@ void R_ExecuteSetViewSize(void) viewheight = vid.height; if (splitscreen) + { viewheight >>= 1; - if (splitscreen > 1) - { - viewwidth >>= 1; + if (splitscreen > 1) + viewwidth >>= 1; } centerx = viewwidth/2; @@ -956,13 +956,9 @@ void R_ExecuteSetViewSize(void) screenheightarray[i] = (INT16)viewheight; } - if (ds_su) - Z_Free(ds_su); - if (ds_sv) - Z_Free(ds_sv); - if (ds_sz) - Z_Free(ds_sz); - + Z_Free(ds_su); + Z_Free(ds_sv); + Z_Free(ds_sz); ds_su = ds_sv = ds_sz = NULL; memset(scalelight, 0xFF, sizeof(scalelight)); diff --git a/src/r_patch.cpp b/src/r_patch.cpp index 60d4acb98..bca733c8b 100644 --- a/src/r_patch.cpp +++ b/src/r_patch.cpp @@ -405,10 +405,8 @@ static void Patch_FreeData(patch_t *patch) }*/ #endif - if (patch->columnofs) - Z_Free(patch->columnofs); - if (patch->columns) - Z_Free(patch->columns); + Z_Free(patch->columnofs); + Z_Free(patch->columns); } void Patch_Free(patch_t *patch) diff --git a/src/r_things.cpp b/src/r_things.cpp index c6cee4df7..8d4f3ce9c 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -392,7 +392,7 @@ boolean R_AddSingleSpriteDef(const char *sprname, spritedef_t *spritedef, UINT16 // allocate space for the frames present and copy sprtemp to it if (spritedef->numframes && // has been allocated - spritedef->numframes < maxframe) // more frames are defined ? + spritedef->numframes < maxframe) // more frames are defined ? { Z_Free(spritedef->spriteframes); diff --git a/src/v_video.c b/src/v_video.c index a92575c96..fde09cc0b 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3716,9 +3716,7 @@ void V_DoPostProcessor(INT32 view, INT32 param) // Make sure table is built if (heatshifter == NULL || lastheight != viewheight) { - if (heatshifter) - Z_Free(heatshifter); - + Z_Free(heatshifter); heatshifter = Z_Calloc(viewheight * sizeof(boolean), PU_STATIC, NULL); for (y = 0; y < viewheight; y++) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index bbf543f1d..b5360bbfc 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -141,7 +141,9 @@ void W_Shutdown(void) if (wad->handle) fclose(wad->handle); + Z_Free(wad->filename); + while (wad->numlumps--) { //Z_Free(wad->lumpinfo[wad->numlumps].longname); @@ -2744,10 +2746,7 @@ void vres_Free(virtres_t* vres) while (vres->numlumps--) { - if (vres->vlumps[vres->numlumps].data) - { - Z_Free(vres->vlumps[vres->numlumps].data); - } + Z_Free(vres->vlumps[vres->numlumps].data); } Z_Free(vres->vlumps); diff --git a/src/z_zone.h b/src/z_zone.h index 90a55b465..38f00c48c 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -91,7 +91,7 @@ void Z_Init(void); // Z_Free and alloc with alignment #ifdef ZDEBUG -#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) +#define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) #define Z_Malloc(s,t,u) Z_Malloc2(s, t, u, __FILE__, __LINE__) #define Z_Calloc(s,t,u) Z_Calloc2(s, t, u, __FILE__, __LINE__) #define Z_Realloc(p,s,t,u) Z_Realloc2(p,s, t, u, __FILE__, __LINE__)