From 80ecd157f66e65e727010ca277d3645379bcd14b Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 4 Jan 2011 22:38:33 +0100 Subject: [PATCH] fix memleak: free con->name before overwriting it --- src/tree.c | 3 +++ src/workspace.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tree.c b/src/tree.c index fd0a3ec7..5f2c3580 100644 --- a/src/tree.c +++ b/src/tree.c @@ -49,6 +49,7 @@ void tree_init() { Output *output; croot = con_new(NULL); + FREE(croot->name); croot->name = "root"; croot->type = CT_ROOT; @@ -60,6 +61,7 @@ void tree_init() { continue; Con *oc = con_new(croot); + FREE(oc->name); oc->name = strdup(output->name); oc->type = CT_OUTPUT; oc->rect = output->rect; @@ -74,6 +76,7 @@ void tree_init() { ws = con_new(NULL); ws->type = CT_WORKSPACE; ws->num = c; + FREE(ws->name); asprintf(&(ws->name), "%d", c); c++; con_attach(ws, oc, false); diff --git a/src/workspace.c b/src/workspace.c index 9ce28e52..eeb756b1 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -46,7 +46,8 @@ Con *workspace_get(const char *num) { x_set_name(workspace, name); free(name); workspace->type = CT_WORKSPACE; - workspace->name = strdup(num); + FREE(workspace->name); + workspace->name = sstrdup(num); /* We set ->num to the number if this workspace’s name consists only of * a positive number. Otherwise it’s a named ws and num will be -1. */ char *end; -- 2.39.5