]> git.sur5r.net Git - i3/i3/commitdiff
i3bar: free output data structures 3022/head
authorOrestis Floros <orestisf1993@gmail.com>
Tue, 26 Sep 2017 11:50:26 +0000 (14:50 +0300)
committerOrestis Floros <orestisf1993@gmail.com>
Sun, 3 Dec 2017 18:25:34 +0000 (20:25 +0200)
i3bar/include/outputs.h
i3bar/src/ipc.c
i3bar/src/main.c
i3bar/src/outputs.c
i3bar/src/xcb.c

index de960270e500186dce9c032e1a548b5d486f1bd7..29a7bcd3825e0b62fb354f233326dde25ea695b7 100644 (file)
@@ -33,6 +33,12 @@ void parse_outputs_json(char* json);
  */
 void init_outputs(void);
 
+/*
+ * free() all outputs data structures.
+ *
+ */
+void free_outputs(void);
+
 /*
  * Returns the output with the given name
  *
index 49c729ae94ef267154bf4830cc7a1329c1894489..cc3563ec0ad0039cc4867f79759c55e16a03e504 100644 (file)
@@ -64,17 +64,14 @@ void got_subscribe_reply(char *reply) {
  */
 void got_output_reply(char *reply) {
     DLOG("Clearing old output configuration...\n");
-    i3_output *o_walk;
-    SLIST_FOREACH(o_walk, outputs, slist) {
-        destroy_window(o_walk);
-    }
-    FREE_SLIST(outputs, i3_output);
+    free_outputs();
 
     DLOG("Parsing outputs JSON...\n");
     parse_outputs_json(reply);
     DLOG("Reconfiguring windows...\n");
     reconfig_windows(false);
 
+    i3_output *o_walk;
     SLIST_FOREACH(o_walk, outputs, slist) {
         kick_tray_clients(o_walk);
     }
index 910e952482f0d788b46747ac0b9bab396242f7c5..069803d4f944289afac72323bf15acd8d24fae03 100644 (file)
@@ -182,7 +182,5 @@ int main(int argc, char **argv) {
     clean_xcb();
     ev_default_destroy();
 
-    free_workspaces();
-
     return 0;
 }
index bd056a700d231a49eadfcee3120bc156364a9d6b..4c9ce6513e9d082d365b0f9264a4ecf6072dc0ce 100644 (file)
@@ -173,6 +173,12 @@ static int outputs_start_map_cb(void *params_) {
     return 1;
 }
 
+static void clear_output(i3_output *output) {
+    FREE(output->name);
+    FREE(output->workspaces);
+    FREE(output->trayclients);
+}
+
 /*
  * We hit the end of a map (rect or a new output)
  *
@@ -199,9 +205,7 @@ static int outputs_end_map_cb(void *params_) {
         if (!handle_output) {
             DLOG("Ignoring output \"%s\", not configured to handle it.\n",
                  params->outputs_walk->name);
-            FREE(params->outputs_walk->name);
-            FREE(params->outputs_walk->workspaces);
-            FREE(params->outputs_walk->trayclients);
+            clear_output(params->outputs_walk);
             FREE(params->outputs_walk);
             FREE(params->cur_key);
             return 1;
@@ -217,6 +221,9 @@ static int outputs_end_map_cb(void *params_) {
         target->primary = params->outputs_walk->primary;
         target->ws = params->outputs_walk->ws;
         target->rect = params->outputs_walk->rect;
+
+        clear_output(params->outputs_walk);
+        FREE(params->outputs_walk);
     }
     return 1;
 }
@@ -260,7 +267,6 @@ void init_outputs(void) {
  */
 void parse_outputs_json(char *json) {
     struct outputs_json_params params;
-
     params.outputs_walk = NULL;
     params.cur_key = NULL;
     params.json = json;
@@ -286,6 +292,27 @@ void parse_outputs_json(char *json) {
     yajl_free(handle);
 }
 
+/*
+ * free() all outputs data structures.
+ *
+ */
+void free_outputs(void) {
+    free_workspaces();
+
+    i3_output *outputs_walk;
+    if (outputs == NULL) {
+        return;
+    }
+    SLIST_FOREACH(outputs_walk, outputs, slist) {
+        destroy_window(outputs_walk);
+        if (outputs_walk->trayclients != NULL && !TAILQ_EMPTY(outputs_walk->trayclients)) {
+            FREE_TAILQ(outputs_walk->trayclients, trayclient);
+        }
+        clear_output(outputs_walk);
+    }
+    FREE_SLIST(outputs, i3_output);
+}
+
 /*
  * Returns the output with the given name
  *
index dfa66ee2db209e66f21dc87eced55864bac4b9d7..815f41fdf3678eea41ad1f4ab4041430925f35f4 100644 (file)
@@ -1517,16 +1517,7 @@ void init_tray_colors(void) {
  *
  */
 void clean_xcb(void) {
-    i3_output *o_walk;
-    free_workspaces();
-    SLIST_FOREACH(o_walk, outputs, slist) {
-        destroy_window(o_walk);
-        FREE(o_walk->trayclients);
-        FREE(o_walk->workspaces);
-        FREE(o_walk->name);
-    }
-    FREE_SLIST(outputs, i3_output);
-    FREE(outputs);
+    free_outputs();
 
     free_font();