diff options
author | Josh Rickmar <jrick@devio.us> | 2012-08-20 19:22:45 -0400 |
---|---|---|
committer | Josh Rickmar <jrick@devio.us> | 2012-08-20 19:22:45 -0400 |
commit | ecc38e92afec8eb237a1cdd20661a932c6c27679 (patch) | |
tree | b3eaf3aee1b2053bf97a1531e5644589919c7a88 | |
parent | 3afd7f4e2bdcb1651e9ab55fd2ae37271c14dfe5 (diff) | |
download | xombrero-ecc38e92afec8eb237a1cdd20661a932c6c27679.tar.gz |
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.
-rw-r--r-- | inputfocus.c | 14 | ||||
-rw-r--r-- | 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); |