diff options
author | portix <portix@gmx.net> | 2011-12-07 01:19:02 +0100 |
---|---|---|
committer | portix <portix@gmx.net> | 2011-12-07 01:19:02 +0100 |
commit | e4daf017a24601f03fd867e10251d4cb39cba8e7 (patch) | |
tree | 53b6a2416f0845b19818843c6a6a1f364aa25cab /src/adblock.c | |
parent | 8746f884baa464d03f0559810fcc55a7a6ac144f (diff) | |
download | dwb-e4daf017a24601f03fd867e10251d4cb39cba8e7.zip |
Fixing memory leaks in plugin-blocker and adblocker
Diffstat (limited to 'src/adblock.c')
-rw-r--r-- | src/adblock.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/adblock.c b/src/adblock.c index f85d158b..c12e7cdb 100644 --- a/src/adblock.c +++ b/src/adblock.c @@ -265,8 +265,6 @@ error_out: void adblock_apply_element_hider(WebKitWebFrame *frame, GList *gl) { GSList *list; - WebKitDOMStyleSheetList *slist = NULL; - WebKitDOMStyleSheet *ssheet = NULL; WebKitWebView *wv = WEBVIEW(gl); WebKitWebDataSource *datasource = webkit_web_frame_get_data_source(frame); @@ -346,19 +344,14 @@ adblock_apply_element_hider(WebKitWebFrame *frame, GList *gl) { g_string_append(css_rule, "{display:none!important;}"); if (frame == webkit_web_view_get_main_frame(wv)) { WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv); - slist = webkit_dom_document_get_style_sheets(doc); - if (slist) { - ssheet = webkit_dom_style_sheet_list_item(slist, 0); - } - if (ssheet) { - webkit_dom_css_style_sheet_insert_rule((void*)ssheet, css_rule->str, 0, NULL); - } - else { - WebKitDOMElement *style = webkit_dom_document_create_element(doc, "style", NULL); - WebKitDOMHTMLHeadElement *head = webkit_dom_document_get_head(doc); - webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(style), css_rule->str, NULL); - webkit_dom_node_append_child(WEBKIT_DOM_NODE(head), WEBKIT_DOM_NODE(style), NULL); + if (VIEW(gl)->status->style == NULL) { + WebKitDOMDocument *doc = webkit_web_view_get_dom_document(WEBVIEW(gl)); + VIEW(gl)->status->style = webkit_dom_document_create_element(doc, "style", NULL); } + WebKitDOMHTMLHeadElement *head = webkit_dom_document_get_head(doc); + webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(VIEW(gl)->status->style), css_rule->str, NULL); + webkit_dom_node_append_child(WEBKIT_DOM_NODE(head), WEBKIT_DOM_NODE(VIEW(gl)->status->style), NULL); + g_object_unref(head); } else { const char *css = css_rule->str; @@ -489,6 +482,7 @@ adblock_before_load_cb(WebKitDOMElement *win, WebKitDOMEvent *event, GList *gl) char *tagname = webkit_dom_element_get_tag_name(src); const char *url = NULL; AdblockAttribute attributes = AA_DOCUMENT; + gboolean ret = false; WebKitDOMDocument *doc = webkit_dom_dom_window_get_document(WEBKIT_DOM_DOM_WINDOW(win)); char *baseURI = webkit_dom_document_get_document_uri(doc); @@ -500,7 +494,7 @@ adblock_before_load_cb(WebKitDOMElement *win, WebKitDOMEvent *event, GList *gl) else if (webkit_dom_element_has_attribute(src, "data")) url = webkit_dom_element_get_attribute(src, "data"); if (url == NULL) - return false; + goto error_out; if (!g_strcmp0(tagname, "IMG")) { attributes |= AA_IMAGE; @@ -513,6 +507,8 @@ adblock_before_load_cb(WebKitDOMElement *win, WebKitDOMEvent *event, GList *gl) if (!g_strcmp0(rel, "stylesheet") || !g_strcmp0(type, "text/css")) { attributes |= AA_STYLESHEET; } + g_free(rel); + g_free(type); } else if (!g_strcmp0(tagname, "OBJECT") || ! g_strcmp0(tagname, "EMBED")) { attributes |= AA_OBJECT; @@ -520,7 +516,12 @@ adblock_before_load_cb(WebKitDOMElement *win, WebKitDOMEvent *event, GList *gl) if (adblock_prepare_match(url, baseURI, attributes)) { webkit_dom_event_prevent_default(event); } - return true; + ret = true; +error_out: + g_object_unref(src); + g_free(tagname); + g_free(baseURI); + return ret; }/*}}}*/ /* adblock_resource_request_cb {{{*/ @@ -604,6 +605,10 @@ adblock_disconnect(GList *gl) { g_signal_handler_disconnect(WEBVIEW(gl), (VIEW(gl)->status->signals[SIG_AD_RESOURCE_REQUEST])); v->status->signals[SIG_AD_RESOURCE_REQUEST] = 0; } + if (VIEW(gl)->status->style != NULL) { + g_object_unref(VIEW(gl)->status->style); + VIEW(gl)->status->style = NULL; + } }/*}}}*/ /* adblock_connect() {{{*/ |