From 455177a3e18f1dd5ae0bf2ca3e7dfc139cc182fc Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 15 Dec 2022 19:23:06 +0000 Subject: [PATCH] G_BuildMapTitle creates Zone memory that must be freed --- src/discord.c | 4 +++- src/g_game.c | 6 +++++- src/m_menu.c | 34 +++++++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/discord.c b/src/discord.c index 3ca9e40b..6926b4e1 100644 --- a/src/discord.c +++ b/src/discord.c @@ -529,8 +529,10 @@ void DRPC_UpdatePresence(void) else { // Map name on tool tip - snprintf(mapname, 48, "Map: %s", G_BuildMapTitle(gamemap)); + char *title = G_BuildMapTitle(gamemap); + snprintf(mapname, 48, "Map: %s", title); discordPresence.largeImageText = mapname; + Z_Free(title); } if (gamestate == GS_LEVEL && Playing()) diff --git a/src/g_game.c b/src/g_game.c index c6b633ce..2b9e2f7a 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6747,7 +6747,11 @@ void G_BeginRecording(void) // Full replay title demo_p += 64; - snprintf(demo.titlename, 64, "%s - %s", G_BuildMapTitle(gamemap), modeattacking ? "Time Attack" : connectedservername); + { + char *title = G_BuildMapTitle(gamemap); + snprintf(demo.titlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + Z_Free(title); + } // demo checksum demo_p += 16; diff --git a/src/m_menu.c b/src/m_menu.c index 4bdc6ee0..9d44ff03 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5577,7 +5577,11 @@ static void DrawReplayHutReplayInfo(void) x += 85; if (mapheaderinfo[demolist[dir_on[menudepthleft]].map-1]) - V_DrawString(x, y, V_SNAPTOTOP, G_BuildMapTitle(demolist[dir_on[menudepthleft]].map)); + { + char *title = G_BuildMapTitle(demolist[dir_on[menudepthleft]].map); + V_DrawString(x, y, V_SNAPTOTOP, title); + Z_Free(title); + } else V_DrawString(x, y, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "Level is not loaded."); @@ -6513,16 +6517,36 @@ static char *M_GetConditionString(condition_t cond) G_TicsToMinutes(cond.requirement, false), G_TicsToSeconds(cond.requirement)); case UC_MAPVISITED: - return va("Visit %s", G_BuildMapTitle(cond.requirement-1)); + { + char *title = G_BuildMapTitle(cond.requirement-1); + char *response = va("Visit %s", title); + Z_Free(title); + return response; + } case UC_MAPBEATEN: - return va("Beat %s", G_BuildMapTitle(cond.requirement-1)); + { + char *title = G_BuildMapTitle(cond.requirement-1); + char *response = va("Beat %s", title); + Z_Free(title); + return response; + } case UC_MAPALLEMERALDS: - return va("Beat %s w/ all emeralds", G_BuildMapTitle(cond.requirement-1)); + { + char *title = G_BuildMapTitle(cond.requirement-1); + char *response = va("Beat %s w/ all emeralds", title); + Z_Free(title); + return response; + } case UC_MAPTIME: - return va("Beat %s in %i:%02i.%02i", G_BuildMapTitle(cond.extrainfo1-1), + { + char *title = G_BuildMapTitle(cond.extrainfo1-1); + char *response = va("Beat %s in %i:%02i.%02i", title, G_TicsToMinutes(cond.requirement, true), G_TicsToSeconds(cond.requirement), G_TicsToCentiseconds(cond.requirement)); + Z_Free(title); + return response; + } case UC_TOTALEMBLEMS: return va("Get %d medals", cond.requirement); case UC_EXTRAEMBLEM: