From 6c7323fded4715e5957bf8792bb76a081ab22a57 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 25 Sep 2006 22:27:41 +0000 Subject: Squash memory leak. Ensure that the icon string's always set to something, even if it's the UTF-8 text if we're unable to convert to the local encoding. svn path=/trunk/netsurf/; revision=2965 --- riscos/wimp.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'riscos') diff --git a/riscos/wimp.c b/riscos/wimp.c index 37c03d96b..f8b512b53 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -217,7 +217,7 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { wimp_icon_state ic; os_error *error; int old_len, len; - char *local_text; + char *local_text = NULL; utf8_convert_ret err; unsigned int button_type; @@ -238,22 +238,26 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { /* A bad encoding should never happen, so assert this */ assert(err != UTF8_CONVERT_BADENC); LOG(("utf8_to_enc failed")); - return; + /* Paranoia */ + local_text = NULL; } - len = strlen(local_text); + len = strlen(local_text ? local_text : text); /* check that the existing text is not the same as the updated text * to stop flicker */ if (ic.icon.data.indirected_text.size && !strncmp(ic.icon.data.indirected_text.text, - local_text, - (unsigned int)ic.icon.data.indirected_text.size - 1)) + local_text ? local_text : text, + (unsigned int)ic.icon.data.indirected_text.size - 1)) { + free(local_text); return; + } /* copy the text across */ old_len = strlen(ic.icon.data.indirected_text.text); if (ic.icon.data.indirected_text.size) { - strncpy(ic.icon.data.indirected_text.text, local_text, + strncpy(ic.icon.data.indirected_text.text, + local_text ? local_text : text, (unsigned int)ic.icon.data.indirected_text.size - 1); ic.icon.data.indirected_text.text[ ic.icon.data.indirected_text.size - 1] = '\0'; @@ -269,6 +273,7 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { LOG(("xwimp_get_caret_position: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); + free(local_text); return; } if ((caret.w == w) && (caret.i == i)) { -- cgit v1.2.3