]> git.sur5r.net Git - i3/i3/commitdiff
fix memleak: free con->name before overwriting it
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 4 Jan 2011 21:38:33 +0000 (22:38 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 4 Jan 2011 21:38:33 +0000 (22:38 +0100)
src/tree.c
src/workspace.c

index fd0a3ec71b1c8f22ca45325218cb5620f5ecb16d..5f2c35801b2893917f9fb223f41a1ec339e153e2 100644 (file)
@@ -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);
index 9ce28e523ae05ec3c675dbf05dc397098c267c0a..eeb756b170da9e4f6a4001fe973cd17acd5d5890 100644 (file)
@@ -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;