Re: [hackers] [surf] Removing a memory leak when u wasn't freed. || Christoph Lohmann

From: Silvan Jegen <s.jegen_AT_gmail.com>
Date: Thu, 6 Feb 2014 09:01:51 +0100

On Thu, Feb 6, 2014 at 6:50 AM, <git_AT_suckless.org> wrote:
> commit 127dc366efeda9afc6086be67b60979af1d71205
> Author: Christoph Lohmann <20h_AT_r-36.net>
> Date: Thu Feb 6 06:47:22 2014 +0100
>
> Removing a memory leak when u wasn't freed.
>
> diff --git a/surf.c b/surf.c
> index c598404..1ec4c62 100644
> --- a/surf.c
> +++ b/surf.c
> _AT_@ -656,7 +656,7 @@ loadstatuschange(WebKitWebView *view, GParamSpec *pspec, Client *c) {
>
> static void
> loaduri(Client *c, const Arg *arg) {
> - char *u, *rp;
> + char *u = NULL, *rp;
> const char *uri = (char *)arg->v;
> Arg a = { .b = FALSE };
> struct stat st;
> _AT_@ -683,9 +683,10 @@ loaduri(Client *c, const Arg *arg) {
> webkit_web_view_load_uri(c->view, u);
> c->progress = 0;
> c->title = copystr(&c->title, u);
> - g_free(u);
> updatetitle(c);
> }
> + if(u != NULL)
> + g_free(u);
> }
>
> static void

Calling g_free with a NULL pointer as an argument is a no-op [1] so I
do not think the NULL check is necessary.

[1] https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-free
Received on Thu Feb 06 2014 - 09:01:51 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 06 2014 - 09:12:15 CET