From ecc38e92afec8eb237a1cdd20661a932c6c27679 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Mon, 20 Aug 2012 19:22:45 -0400 Subject: ref/unref t->active before it is set or unset This should fix any crashes when determining if t->active is an active input element or not. The pointer is from a function which returns transfer none, so if we want to keep it alive (we do), we need manually add reference to it, and unrefernce it so it is freed. --- inputfocus.c | 14 ++++++++++++-- xombrero.c | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/inputfocus.c b/inputfocus.c index 23bbd71..eb46841 100644 --- a/inputfocus.c +++ b/inputfocus.c @@ -174,6 +174,8 @@ focus_input(struct tab *t) rv = 1; /* found */ goto done; } else { + if (t->active) + g_object_unref(t->active); t->active = NULL; if (t->active_text) { g_free(t->active_text); @@ -280,8 +282,10 @@ dom_is_input(struct tab *t, char **text) aa = (WebKitDOMHTMLElement*)a; if (WEBKIT_DOM_IS_HTML_ELEMENT(aa) && webkit_dom_html_element_get_is_content_editable(aa)) { - if (t->active == NULL) + if (t->active == NULL) { t->active = a; + g_object_ref(t->active); + } *text = get_element_text((WebKitDOMNode *)a); if (t->active_text == NULL) t->active_text = g_strdup(*text); @@ -295,14 +299,18 @@ dom_is_input(struct tab *t, char **text) if (node_is_valid_entry((WebKitDOMNode *)a)) { if (!node_is_valid_entry((WebKitDOMNode *)t->active)) { + if (t->active) + g_object_unref(t->active); t->active = NULL; if (t->active_text) { g_free(t->active_text); t->active_text = NULL; } } - if (t->active == NULL) + if (t->active == NULL) { t->active = a; + g_object_ref(t->active); + } *text = get_element_text((WebKitDOMNode *)a); if (t->active_text == NULL) t->active_text = g_strdup(*text); @@ -345,6 +353,8 @@ command_mode(struct tab *t, struct karg *args) t->mode = args->i; if (!node_is_valid_entry((WebKitDOMNode *)t->active)) { + if (t->active) + g_object_unref(t->active); t->active = NULL; if (t->active_text) { g_free(t->active_text); diff --git a/xombrero.c b/xombrero.c index 172b3ee..567fc6f 100644 --- a/xombrero.c +++ b/xombrero.c @@ -4308,6 +4308,8 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) /* DOM is changing, unreference the previous focused element */ #if WEBKIT_CHECK_VERSION(1, 5, 0) + if (t->active) + g_object_unref(t->active); t->active = NULL; if (t->active_text) { g_free(t->active_text); -- cgit 1.4.1-2-gfad0