From 5d1f03b77fcbb14367a38bd3cc87a6de7d20529a Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Feb 2026 09:46:36 -0500 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/hu_stuff.c | 15 ++++----------- 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/p_spec.c | 3 +-- src/r_main.cpp | 10 +++------- src/r_textures.c | 3 +-- src/v_video.c | 4 +--- src/w_wad.cpp | 5 +---- src/z_zone.cpp | 1 + src/z_zone.h | 2 +- 15 files changed, 34 insertions(+), 77 deletions(-) diff --git a/src/f_finale.c b/src/f_finale.c index b8dc87520..cac185ea1 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1811,9 +1811,7 @@ void F_StartWaitingPlayers(void) #ifdef NOWAY randskin = M_RandomKey(numskins); - if (waitcolormap) - Z_Free(waitcolormap); - + Z_Free(waitcolormap); waitcolormap = R_GetTranslationColormap(randskin, skins[randskin].prefcolor, 0); sprdef = &skins[randskin].sprites[P_GetSkinSprite2(&skins[randskin], SPR2_FSTN, NULL)]; diff --git a/src/filesrch.c b/src/filesrch.c index f09c24aab..3b5c1b922 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -283,8 +283,7 @@ void closefilemenu(boolean validsize) coredirmenu = NULL; } - if (refreshdirname) - Z_Free(refreshdirname); + Z_Free(refreshdirname); refreshdirname = NULL; } @@ -312,8 +311,7 @@ void searchfilemenu(char *tempname) if (!menusearch.length) { - if (dirmenu) - Z_Free(dirmenu); + Z_Free(dirmenu); dirmenu = coredirmenu; sizedirmenu = sizecoredirmenu; @@ -355,8 +353,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; } @@ -480,8 +478,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/hu_stuff.c b/src/hu_stuff.c index f272b09f6..69d993ea8 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -916,8 +916,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) if ((cv_chatnotifications.value) && (flags & HU_SHOUT)) S_StartSound(NULL, sfx_sysmsg); - 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 @@ -1418,9 +1417,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); @@ -1509,9 +1506,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: @@ -1622,9 +1617,7 @@ static void HU_drawChatLog(INT32 offset) dy += charheight; dx = 0; - - if (msg) - Z_Free(msg); + Z_Free(msg); } diff --git a/src/i_tcp.c b/src/i_tcp.c index 798b2a9ce..bfe3cf7a1 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1550,11 +1550,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); return true; @@ -1567,11 +1564,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); return true; diff --git a/src/k_stats.c b/src/k_stats.c index e5bcef4a9..658f8ae3f 100644 --- a/src/k_stats.c +++ b/src/k_stats.c @@ -107,8 +107,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 3cac9b64c..b95483875 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -143,18 +143,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 7d1287ccc..2059ee6d4 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -745,16 +745,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 08c761108..83e7cb643 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -67,12 +67,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/p_spec.c b/src/p_spec.c index e821d2bb8..75b7181ef 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -8076,8 +8076,7 @@ void P_SpawnSpecials(boolean fromnetsave) // 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_main.cpp b/src/r_main.cpp index e813d0e10..e1192ad93 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1025,13 +1025,9 @@ void R_ExecuteSetViewSize(void) // planes if (rendermode == render_soft) { - 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; } diff --git a/src/r_textures.c b/src/r_textures.c index 530b929e7..cabc21cb0 100644 --- a/src/r_textures.c +++ b/src/r_textures.c @@ -1977,8 +1977,7 @@ static void PaletteTextureHack(const char **name) 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/v_video.c b/src/v_video.c index f766d4b7e..810781773 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -3922,9 +3922,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 df4158d01..b076d1507 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -2801,10 +2801,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); Z_Free(vres); diff --git a/src/z_zone.cpp b/src/z_zone.cpp index e1c38896c..10f53d869 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -125,6 +125,7 @@ void Z_Init(void) * * \param ptr A pointer to allocated memory, * assumed to have been allocated with Z_Malloc/Z_Calloc. + * These free functions also automatically check for NULL! * \sa Z_FreeTags */ void Z_Free2(void *ptr, const char *file, INT32 line) diff --git a/src/z_zone.h b/src/z_zone.h index 597a93547..8fedf6961 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -85,7 +85,7 @@ void Z_Init(void); // Zone memory allocation // -// Z_Free and alloc with alignment +// Z_Free and alloc with alignment, automatically checks for NULL. #define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) #define Z_MallocAlign(s,t,u,a) Z_Malloc2(s, t, u, a, __FILE__, __LINE__) #define Z_CallocAlign(s,t,u,a) Z_Calloc2(s, t, u, a, __FILE__, __LINE__)