From aaf20dd745ccd3a2cf152b2cc6f7bd3617b78485 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Mon, 27 Feb 2012 16:10:50 -0600 Subject: [PATCH] fix a couple of mem leaks, bad stevan! fix provided by ber_t on forum --- history.c | 34 +++++++++++++++++++++------------- xxxterm.c | 15 ++++++++++----- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/history.c b/history.c index a536275..53f5ff7 100644 --- a/history.c +++ b/history.c @@ -182,23 +182,31 @@ save_global_history_to_disk(struct tab *t) return (0); } -/* Marshall the internal record of visited URIs into a Javascript hash table in - * string form. */ +/* + * Marshall the internal record of visited URIs into a Javascript hash table in + * string form. + */ char * color_visited_helper(void) { - char *s = NULL; + char *d, *s = NULL, *t; struct history *h; RB_FOREACH_REVERSE(h, history_list, &hl) { if (s == NULL) s = g_strdup_printf("'%s':'dummy'", h->uri); - else - s = g_strjoin(",", s, - g_strdup_printf("'%s':'dummy'", h->uri), NULL); + else { + d = g_strdup_printf("'%s':'dummy'", h->uri); + t = g_strjoin(",", s, d, NULL); + g_free(d); + g_free(s); + s = t; + } } - s = g_strdup_printf("{%s}", s); + t = g_strdup_printf("{%s}", s); + g_free(s); + s = t; DNPRINTF(XT_D_VISITED, "%s: s = %s\n", __func__, s); @@ -208,31 +216,31 @@ color_visited_helper(void) int color_visited(struct tab *t, char *visited) { - char *s; + char *s, *v; if (t == NULL || visited == NULL) { show_oops(NULL, "%s: invalid parameters", __func__); return (1); } - /* Create a string representing an annonymous Javascript function, which + /* + * Create a string representing an annonymous Javascript function, which * takes a hash table of visited URIs as an argument, goes through the * links at the current web page and colors them if they indeed been * visited. */ + v = g_strdup_printf("(%s);", visited), s = g_strconcat( "(function(visitedUris) {", " for (var i = 0; i < document.links.length; i++)", " if (visitedUris[document.links[i].href])", " document.links[i].style.color = 'purple';", "})", - /* Apply the annonymous function to the hash table containing - * visited URIs. */ - g_strdup_printf("(%s);", visited), - NULL); + v, NULL); run_script(t, s); g_free(s); + g_free(v); g_free(visited); return (0); diff --git a/xxxterm.c b/xxxterm.c index b0d97c1..c5f88fd 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -443,18 +443,23 @@ is_g_object_setting(GObject *o, char *str) { guint n_props = 0, i; GParamSpec **proplist; + int rv = 0; - if (! G_IS_OBJECT(o)) + if (!G_IS_OBJECT(o)) return (0); proplist = g_object_class_list_properties(G_OBJECT_GET_CLASS(o), &n_props); - for (i=0; i < n_props; i++) { - if (! strcmp(proplist[i]->name, str)) - return (1); + for (i = 0; i < n_props; i++) { + if (! strcmp(proplist[i]->name, str)) { + rv = 1; + break; + } } - return (0); + + g_free(proplist); + return (rv); } struct tab * -- 2.11.4.GIT