summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Rameau <quinq+hackers@fifth.space>2015-10-31 12:34:31 +0100
committerChristoph Lohmann <20h@r-36.net>2015-10-31 17:50:03 +0100
commitd84fe71094e5eb2598344da5c6a1d6f64381142c (patch)
treec568cef67eddbc045c2b35f1ceb69187d49455f1
parentd486169fa47c0aa2c038df81fe23232a1cefff4b (diff)
downloadsurf-d84fe71094e5eb2598344da5c6a1d6f64381142c.tar.gz
surf-d84fe71094e5eb2598344da5c6a1d6f64381142c.tar.bz2
surf-d84fe71094e5eb2598344da5c6a1d6f64381142c.zip
Fix style files handling: stop leaking strings.
Everytime getstyle() was being called, we returned newly allocated strings without ever freing them. Now uri stylefiles only get allocated once at setup(). Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r--surf.c36
1 files changed, 22 insertions, 14 deletions
diff --git a/surf.c b/surf.c
index 28bffef..55ffd84 100644
--- a/surf.c
+++ b/surf.c
@@ -154,7 +154,7 @@ static const char *getatom(Client *c, int a);
static void gettogglestat(Client *c);
static void getpagestat(Client *c);
static char *geturi(Client *c);
-static gchar *getstyle(const char *uri);
+static const gchar *getstyle(const char *uri);
static void handleplumb(Client *c, WebKitWebView *w, const gchar *uri);
@@ -645,20 +645,21 @@ geturi(Client *c)
return uri;
}
-gchar *
+const gchar *
getstyle(const char *uri)
{
int i;
if (stylefile != NULL)
- return g_strconcat("file://", stylefile, NULL);
+ return stylefile;
for (i = 0; i < LENGTH(styles); i++) {
if (styles[i].regex && !regexec(&(styles[i].re), uri, 0,
NULL, 0))
- return g_strconcat("file://", styles[i].style, NULL);
+ return styles[i].style;
}
- return g_strdup("");
+
+ return "";
}
void
@@ -1285,8 +1286,8 @@ void
setup(void)
{
int i;
- char *proxy;
- char *new_proxy;
+ char *proxy, *new_proxy;
+ char *styledirfile, *stylepath;
SoupURI *puri;
SoupSession *s;
GError *error = NULL;
@@ -1306,8 +1307,8 @@ setup(void)
cookiefile = buildfile(cookiefile);
scriptfile = buildfile(scriptfile);
cachefolder = buildpath(cachefolder);
- styledir = buildpath(styledir);
if (stylefile == NULL) {
+ styledir = buildpath(styledir);
for (i = 0; i < LENGTH(styles); i++) {
if (regcomp(&(styles[i].re), styles[i].regex,
REG_EXTENDED)) {
@@ -1316,11 +1317,19 @@ setup(void)
styles[i].regex);
styles[i].regex = NULL;
}
- styles[i].style = buildfile(g_strconcat(styledir, "/",
- styles[i].style, NULL));
+ styledirfile = g_strconcat(styledir, "/",
+ styles[i].style, NULL);
+ stylepath = buildfile(styledirfile);
+ styles[i].style = g_strconcat("file://", stylepath,
+ NULL);
+ g_free(styledirfile);
+ g_free(stylepath);
}
+ g_free(styledir);
} else {
- stylefile = buildfile(stylefile);
+ stylepath = buildfile(stylefile);
+ stylefile = g_strconcat("file://", stylepath, NULL);
+ g_free(stylepath);
}
/* request handler */
@@ -1523,11 +1532,10 @@ void
togglestyle(Client *c, const Arg *arg)
{
WebKitWebSettings *settings = webkit_web_view_get_settings(c->view);
- char *uri;
enablestyles = !enablestyles;
- uri = enablestyles ? getstyle(geturi(c)) : g_strdup("");
- g_object_set(G_OBJECT(settings), "user-stylesheet-uri", uri, NULL);
+ g_object_set(G_OBJECT(settings), "user-stylesheet-uri",
+ enablestyles ? getstyle(geturi(c)) : "", NULL);
updatetitle(c);
}