From f738578dc16d21220d1cb031692c6305af7e27ba Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 20 Mar 2018 23:15:21 -0400 Subject: [PATCH] Use a copy of the input text string for message-box. --- common/message-box.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/common/message-box.c b/common/message-box.c index 1950eaf..3661856 100644 --- a/common/message-box.c +++ b/common/message-box.c @@ -5,7 +5,7 @@ typedef struct uint32_t width; uint32_t height; color_t *bg; - const char *text; + char *text; } MessageBox; MessageBox currMsgBox; @@ -147,7 +147,11 @@ void menuCreateMsgBox(int width, int height, const char *text) { if (menuIsMsgBoxOpen()) return; - currMsgBox = (MessageBox) { width, height, NULL, text }; + char *new_text = strdup(text); + if (new_text==NULL) + return; + + currMsgBox = (MessageBox) { width, height, NULL, new_text }; currMsgBox.bg = malloc(currMsgBox.width*currMsgBox.height*4); @@ -167,5 +171,9 @@ void menuCloseMsgBox() { } currMsgBox.width = currMsgBox.height = 0; - currMsgBox.text = NULL; + + if (currMsgBox.text) { + free(currMsgBox.text); + currMsgBox.text = NULL; + } }