From 2ac33942a259e58478990f35f9ac01d662596aa0 Mon Sep 17 00:00:00 2001 From: Hannu Hanhi Date: Fri, 31 Jan 2020 23:04:45 +0200 Subject: [PATCH] Chat drawing memory leak fix from SRB2 repo --- src/hu_stuff.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index f343f12b7..1d0f8b4c2 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -1482,7 +1482,7 @@ static void HU_drawMiniChat(void) for (; i>0; i--) { - const char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); + char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i-1]); size_t j = 0; INT32 linescount = 0; @@ -1524,6 +1524,8 @@ static void HU_drawMiniChat(void) dy = 0; dx = 0; msglines += linescount+1; + if (msg) + Z_Free(msg); } y = chaty - charheight*(msglines+1); @@ -1550,7 +1552,7 @@ static void HU_drawMiniChat(void) INT32 timer = ((cv_chattime.value*TICRATE)-chat_timers[i]) - cv_chattime.value*TICRATE+9; // see below... INT32 transflag = (timer >= 0 && timer <= 9) ? (timer*V_10TRANS) : 0; // you can make bad jokes out of this one. size_t j = 0; - const char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. + char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_mini[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; while(msg[j]) // iterate through msg @@ -1596,6 +1598,8 @@ static void HU_drawMiniChat(void) } dy += charheight; dx = 0; + if (msg) + Z_Free(msg); } // decrement addy and make that shit smooth: @@ -1651,7 +1655,7 @@ static void HU_drawChatLog(INT32 offset) { INT32 clrflag = 0; INT32 j = 0; - const char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_log[i]); // get the current message, and word wrap it. + char *msg = CHAT_WordWrap(x+2, boxw-(charwidth*2), V_SNAPTOBOTTOM|V_SNAPTOLEFT|V_ALLOWLOWERCASE, chat_log[i]); // get the current message, and word wrap it. UINT8 *colormap = NULL; while(msg[j]) // iterate through msg { @@ -1691,6 +1695,8 @@ static void HU_drawChatLog(INT32 offset) } dy += charheight; dx = 0; + if (msg) + Z_Free(msg); }