surf-adblock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 60429d74233b5c0f61db8bf5725b4fdda92faa77
parent 7f8481c1af8ddf550336c6ee273a3ffb1e9fb1fb
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sun, 17 Jul 2016 20:53:50 +0200

cleanup on global css rules parsing error

All possible errors there would have occurred before binding to the
webkit signals so we just need to free allocated memory and return.

Diffstat:
surf-adblock.c | 38+++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/surf-adblock.c b/surf-adblock.c @@ -112,6 +112,27 @@ static Page *pages; static struct filterrule *rules; static void +cleanup(void) +{ + struct filterrule *r; + struct filterdomain *d; + + free(globalcss.data); + + for (r = rules; r; r = rules) { + for (d = r->domains; d; d = r->domains) { + free(d->domain); + r->domains = d->next; + free(d); + } + free(r->css); + free(r->uri); + rules = r->next; + free(r); + } +} + +static void weprintf(const char *fmt, ...) { va_list ap; @@ -835,8 +856,11 @@ webpagecreated(WebKitWebExtension *e, WebKitWebPage *p, gpointer unused) { Page *np; - if (!(np = newpage(p))) + if (!(np = newpage(p))) { + weprintf("cannot associate webext with new page: %s\n", + strerror(errno)); return; + } g_signal_connect(p, "document-loaded", G_CALLBACK(documentloaded), np); g_signal_connect(p, "send-request", G_CALLBACK(sendrequest), np); @@ -889,11 +913,19 @@ webkit_web_extension_initialize(WebKitWebExtension *ext) continue; len = strlen(r->css); - if (string_append(&globalcss, r->css, strlen(r->css)) < len) + if (string_append(&globalcss, r->css, strlen(r->css)) < len) { + weprintf("cannot load global css selectors " + "in memory\n"); + cleanup(); return; + } len = sizeof("{display:none;}") - 1; - if (string_append(&globalcss, "{display:none;}", len) < len) + if (string_append(&globalcss, "{display:none;}", len) < len) { + weprintf("cannot append css rule " + "to global css selectors\n"); + cleanup(); return; + } } g_signal_connect(ext, "page-created", G_CALLBACK(webpagecreated), NULL);