summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar taiyu <taiyu.len@gmail.com>2015-09-06 23:22:02 -0700
committerLibravatar taiyu <taiyu.len@gmail.com>2015-09-06 23:22:02 -0700
commitb7de289332f74d6a7cc29f2dbeec059ec2ea1d70 (patch)
tree39746743942807ae8c1bf058024096550b7c982d
parentconfig_path cleanup (diff)
downloadsway-b7de289332f74d6a7cc29f2dbeec059ec2ea1d70.tar.gz
sway-b7de289332f74d6a7cc29f2dbeec059ec2ea1d70.tar.zst
sway-b7de289332f74d6a7cc29f2dbeec059ec2ea1d70.zip
free config when reloading
-rw-r--r--sway/config.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/sway/config.c b/sway/config.c
index 02805136..d2986a77 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -11,7 +11,7 @@
11#include "layout.h" 11#include "layout.h"
12#include "input_state.h" 12#include "input_state.h"
13 13
14struct sway_config *config; 14struct sway_config *config = NULL;
15 15
16static bool file_exists(const char *path) { 16static bool file_exists(const char *path) {
17 return access(path, R_OK) != -1; 17 return access(path, R_OK) != -1;
@@ -59,27 +59,41 @@ void free_mode(struct sway_mode *mode) {
59 59
60void free_config(struct sway_config *config) { 60void free_config(struct sway_config *config) {
61 int i; 61 int i;
62 for (i = 0; i < config->symbols->length; ++i) {
63 struct sway_variable *var = config->symbols->items[i];
64 free(var->name);
65 free(var->value);
66 free(var);
67 }
68 list_free(config->symbols);
69
62 for (i = 0; i < config->modes->length; ++i) { 70 for (i = 0; i < config->modes->length; ++i) {
63 free_mode((struct sway_mode *)config->modes->items[i]); 71 free_mode(config->modes->items[i]);
64 } 72 }
65 free_flat_list(config->modes); 73 list_free(config->modes);
74
75 for (i = 0; i < config->cmd_queue->length; ++i) {
76 free(config->cmd_queue->items[i]);
77 }
78 list_free(config->cmd_queue);
79
66 for (i = 0; i < config->workspace_outputs->length; ++i) { 80 for (i = 0; i < config->workspace_outputs->length; ++i) {
67 struct workspace_output *wso = config->workspace_outputs->items[i]; 81 struct workspace_output *wso = config->workspace_outputs->items[i];
68 free(wso->output); 82 free(wso->output);
69 free(wso->workspace); 83 free(wso->workspace);
84 free(wso);
70 } 85 }
71 free_flat_list(config->workspace_outputs); 86 list_free(config->workspace_outputs);
72 free_flat_list(config->cmd_queue); 87
73 for (i = 0; i < config->symbols->length; ++i) { 88 for (i = 0; i < config->output_configs->length; ++i) {
74 struct sway_variable *sym = config->symbols->items[i]; 89 struct output_config *oc = config->output_configs->items[i];
75 free(sym->name); 90 free(oc->name);
76 free(sym->value); 91 free(oc);
77 } 92 }
78 free_flat_list(config->symbols); 93 list_free(config->output_configs);
79 free_flat_list(config->output_configs); 94 free(config);
80} 95}
81 96
82
83static char *get_config_path(void) { 97static char *get_config_path(void) {
84 char *config_path = NULL; 98 char *config_path = NULL;
85 char *paths[3] = {getenv("HOME"), getenv("XDG_CONFIG_HOME"), ""}; 99 char *paths[3] = {getenv("HOME"), getenv("XDG_CONFIG_HOME"), ""};
@@ -244,6 +258,9 @@ _continue:
244 temp_config->reloading = false; 258 temp_config->reloading = false;
245 arrange_windows(&root_container, -1, -1); 259 arrange_windows(&root_container, -1, -1);
246 } 260 }
261 if (config) {
262 free_config(config);
263 }
247 config = temp_config; 264 config = temp_config;
248 265
249 return success; 266 return success;