free config when reloading

This commit is contained in:
taiyu 2015-09-06 23:22:02 -07:00
parent 5408d34c9c
commit b7de289332

View file

@ -11,7 +11,7 @@
#include "layout.h" #include "layout.h"
#include "input_state.h" #include "input_state.h"
struct sway_config *config; struct sway_config *config = NULL;
static bool file_exists(const char *path) { static bool file_exists(const char *path) {
return access(path, R_OK) != -1; return access(path, R_OK) != -1;
@ -59,26 +59,40 @@ void free_mode(struct sway_mode *mode) {
void free_config(struct sway_config *config) { void free_config(struct sway_config *config) {
int i; int i;
for (i = 0; i < config->modes->length; ++i) { for (i = 0; i < config->symbols->length; ++i) {
free_mode((struct sway_mode *)config->modes->items[i]); struct sway_variable *var = config->symbols->items[i];
free(var->name);
free(var->value);
free(var);
} }
free_flat_list(config->modes); list_free(config->symbols);
for (i = 0; i < config->modes->length; ++i) {
free_mode(config->modes->items[i]);
}
list_free(config->modes);
for (i = 0; i < config->cmd_queue->length; ++i) {
free(config->cmd_queue->items[i]);
}
list_free(config->cmd_queue);
for (i = 0; i < config->workspace_outputs->length; ++i) { for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i]; struct workspace_output *wso = config->workspace_outputs->items[i];
free(wso->output); free(wso->output);
free(wso->workspace); free(wso->workspace);
free(wso);
} }
free_flat_list(config->workspace_outputs); list_free(config->workspace_outputs);
free_flat_list(config->cmd_queue);
for (i = 0; i < config->symbols->length; ++i) {
struct sway_variable *sym = config->symbols->items[i];
free(sym->name);
free(sym->value);
}
free_flat_list(config->symbols);
free_flat_list(config->output_configs);
}
for (i = 0; i < config->output_configs->length; ++i) {
struct output_config *oc = config->output_configs->items[i];
free(oc->name);
free(oc);
}
list_free(config->output_configs);
free(config);
}
static char *get_config_path(void) { static char *get_config_path(void) {
char *config_path = NULL; char *config_path = NULL;
@ -244,6 +258,9 @@ _continue:
temp_config->reloading = false; temp_config->reloading = false;
arrange_windows(&root_container, -1, -1); arrange_windows(&root_container, -1, -1);
} }
if (config) {
free_config(config);
}
config = temp_config; config = temp_config;
return success; return success;