From ab8b3b33c4adac4f262619b89f21228ced5575d8 Mon Sep 17 00:00:00 2001 From: Walther Maldonado Date: Tue, 17 Feb 2015 18:03:53 -0500 Subject: xtp-meaning freed memory usage fix --- about.c | 14 +++++--------- xombrero.c | 50 +++++++++++++++++++++++++------------------------- xombrero.h | 1 + 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/about.c b/about.c index 0359c0f..e6d688e 100644 --- a/about.c +++ b/about.c @@ -182,7 +182,7 @@ void load_webkit_string(struct tab *t, const char *str, gchar *title, int nohist) { char file[PATH_MAX]; - int i; + int i, xtp_meaning; if (g_signal_handler_is_connected(t->wv, t->progress_handle)) g_signal_handler_disconnect(t->wv, t->progress_handle); @@ -194,12 +194,12 @@ load_webkit_string(struct tab *t, const char *str, gchar *title, int nohist) g_object_ref(t->item); } - t->xtp_meaning = XT_XTP_TAB_MEANING_NORMAL; + xtp_meaning = XT_XTP_TAB_MEANING_NORMAL; if (title) { - /* set t->xtp_meaning */ + /* set xtp_meaning */ for (i = 0; i < LENGTH(about_list); i++) if (!strcmp(title, about_list[i].name)) { - t->xtp_meaning = i; + xtp_meaning = i; break; } @@ -213,11 +213,7 @@ load_webkit_string(struct tab *t, const char *str, gchar *title, int nohist) xt_icon_from_file(t, file); } - if (t->xtp_meaning == XT_XTP_TAB_MEANING_NORMAL && - t->session_key != NULL) { - g_free(t->session_key); - t->session_key = NULL; - } + set_xtp_meaning(t, xtp_meaning); t->progress_handle = g_signal_connect(t->wv, "notify::progress", G_CALLBACK(webview_progress_changed_cb), t); diff --git a/xombrero.c b/xombrero.c index 11d5c6c..35d3911 100644 --- a/xombrero.c +++ b/xombrero.c @@ -857,11 +857,7 @@ set_normal_tab_meaning(struct tab *t) if (t == NULL) return; - t->xtp_meaning = XT_XTP_TAB_MEANING_NORMAL; - if (t->session_key != NULL) { - g_free(t->session_key); - t->session_key = NULL; - } + set_xtp_meaning(t, XT_XTP_TAB_MEANING_NORMAL); } void @@ -929,22 +925,34 @@ done: const gchar * get_uri(struct tab *t) { - const gchar *uri = NULL; + const gchar *uri; if (webkit_web_view_get_load_status(t->wv) == WEBKIT_LOAD_FAILED && !t->download_requested) return (NULL); if (t->xtp_meaning == XT_XTP_TAB_MEANING_NORMAL) uri = webkit_web_view_get_uri(t->wv); - else { + else + uri = t->tmp_uri; + return (uri); +} + +void +set_xtp_meaning(struct tab *t, int tab_meaning) +{ + t->xtp_meaning = tab_meaning; + if (tab_meaning == XT_XTP_TAB_MEANING_NORMAL) { + if (t->session_key != NULL) { + g_free(t->session_key); + t->session_key = NULL; + } + } else { /* use tmp_uri to make sure it is g_freed */ if (t->tmp_uri) g_free(t->tmp_uri); t->tmp_uri = g_strdup_printf("%s%s", XT_URI_ABOUT, - about_list[t->xtp_meaning].name); - uri = t->tmp_uri; + about_list[t->xtp_meaning].name); } - return (uri); } const gchar * @@ -2025,7 +2033,7 @@ check_cert_changes(struct tab *t, GTlsCertificate *cert, const char *file, const break; if ((w = wl_find(soupuri->host, &svil)) != NULL) break; - t->xtp_meaning = XT_XTP_TAB_MEANING_SV; + set_xtp_meaning(t, XT_XTP_TAB_MEANING_SV); args.s = g_strdup((char *)uri); xtp_page_sv(t, &args); ret = 1; @@ -4144,7 +4152,6 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) const gchar *uri = NULL; struct history *h, find; struct karg a; - gchar *tmp_uri = NULL; #if !GTK_CHECK_VERSION(3, 0, 0) gchar *text, *base; #endif @@ -4268,32 +4275,26 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) /* 2 */ if ((uri = get_uri(t)) == NULL) return; - /* - * js_autorun calls get_uri which frees t->tmp_uri if on an - * "about:" page. On "about:" pages, uri points to t->tmp_uri. - * I.e. we will use freed memory. Prevent that. - */ - tmp_uri = g_strdup(uri); /* autorun some js if enabled */ js_autorun(t); input_autofocus(t); - if (!strncmp(tmp_uri, "http://", strlen("http://")) || - !strncmp(tmp_uri, "https://", strlen("https://")) || - !strncmp(tmp_uri, "file://", strlen("file://"))) { - find.uri = (gchar *)tmp_uri; + if (!strncmp(uri, "http://", strlen("http://")) || + !strncmp(uri, "https://", strlen("https://")) || + !strncmp(uri, "file://", strlen("file://"))) { + find.uri = (gchar *)uri; h = RB_FIND(history_list, &hl, &find); if (!h) - insert_history_item(tmp_uri, + insert_history_item(uri, get_title(t, FALSE), time(NULL)); else h->time = time(NULL); } if (statusbar_style == XT_STATUSBAR_URL) - set_status(t, "%s", (char *)tmp_uri); + set_status(t, "%s", (char *)uri); else set_status(t, "%s", get_title(t, FALSE)); gtk_widget_set_sensitive(GTK_WIDGET(t->stop), FALSE); @@ -4301,7 +4302,6 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) gtk_spinner_stop(GTK_SPINNER(t->spinner)); gtk_widget_hide(t->spinner); #endif - g_free(tmp_uri); break; #if WEBKIT_CHECK_VERSION(1, 1, 18) diff --git a/xombrero.h b/xombrero.h index 45100f9..303ef1c 100644 --- a/xombrero.h +++ b/xombrero.h @@ -402,6 +402,7 @@ GtkWidget *create_window(const gchar *); void show_oops(struct tab *, const char *, ...); gchar *get_html_page(gchar *, gchar *, gchar *, bool); const gchar *get_uri(struct tab *); +void set_xtp_meaning(struct tab *, int); const gchar *get_title(struct tab *, bool); void load_uri(struct tab *t, const gchar *uri); gboolean match_uri(const gchar *uri, const gchar *key); -- cgit 1.4.1-2-gfad0