From 6d3a812ff3ed1cd926b3762d576b3207143f188d Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 12 Dec 2022 16:44:40 +0000 Subject: [PATCH] Fix some G_BuildMapTitle memory leaks (found while writing the next commit) --- src/discord.c | 4 +++- src/g_demo.c | 6 +++++- src/k_menudraw.c | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/discord.c b/src/discord.c index 0e9cb35c9..2fcad7833 100644 --- a/src/discord.c +++ b/src/discord.c @@ -540,7 +540,9 @@ 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); + Z_Free(title); discordPresence.largeImageText = mapname; } diff --git a/src/g_demo.c b/src/g_demo.c index 9d4f1123a..e47d8ba28 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2358,7 +2358,11 @@ void G_BeginRecording(void) // Full replay title demo_p += 64; - snprintf(demo.titlename, 64, "%s - %s", G_BuildMapTitle(gamemap), modeattacking ? "Record Attack" : connectedservername); + { + char *title = G_BuildMapTitle(gamemap); + snprintf(demo.titlename, 64, "%s - %s", title, modeattacking ? "Record Attack" : connectedservername); + Z_Free(title); + } // demo checksum demo_p += 16; diff --git a/src/k_menudraw.c b/src/k_menudraw.c index a651a6cb4..9c6e2de64 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -3970,7 +3970,11 @@ static void M_DrawReplayHutReplayInfo(menudemo_t *demoref) x += 85; if (demoref->map < nummapheaders && mapheaderinfo[demoref->map]) - V_DrawString(x, y, V_SNAPTOTOP, G_BuildMapTitle(demoref->map+1)); + { + char *title = G_BuildMapTitle(demoref->map+1); + 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.");