[PATCH 2/6] Free some nickname related memory in gtk-gui.c
Lubomir I. Ivanov
neolit123 at gmail.com
Sat Dec 22 13:34:20 PST 2012
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
init_ui():
- We add the char pointer "old_token" and free it afterwards, since
once "next_token" is changed it no longer points to the allocated heap
location the mapper returned.
- remember_dc() seems to always (?) allocate memory for the passed
nickname string to it, therefore we don't need to allocate memory
at the "nickname" pointer before calling the function.
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
gtk-gui.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gtk-gui.c b/gtk-gui.c
index c22d2b5..634013a 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1204,10 +1204,10 @@ void init_ui(int *argcp, char ***argvp)
conf_value = subsurface_get_conf("dc_nicknames", PREF_STRING);
nicknamestring = strdup("");
if (conf_value) {
- char *next_token, *nickname;
+ char *next_token, *old_token, *nickname;
uint32_t deviceid;
int len;
- next_token = strdup(conf_value);
+ next_token = old_token = strdup(conf_value);
len = strlen(next_token);
while ((next_token = g_utf8_strchr(next_token, len, '{')) != NULL) {
/* replace the '{' so we keep looking in case any test fails */
@@ -1220,13 +1220,13 @@ void init_ui(int *argcp, char ***argvp)
if (!namestart || !nameend)
continue;
*nameend = '\0';
- nickname = strdup(namestart + 1);
+ nickname = namestart + 1;
remember_dc(deviceid, nickname, FALSE);
next_token = nameend + 1;
};
}
free((void *)conf_value);
- free(next_token);
+ free((void *)old_token);
}
error_info_bar = NULL;
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
--
1.7.11.msysgit.0
More information about the subsurface
mailing list