Merge pull request #3022 from orestisf1993/i3bar-leaks

Fix i3bar leaks
This commit is contained in:
Ingo Bürk 2017-12-03 19:51:25 +01:00 committed by GitHub
commit 458e2a2e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 22 deletions

View File

@ -33,6 +33,12 @@ void parse_outputs_json(char* json);
*/ */
void init_outputs(void); void init_outputs(void);
/*
* free() all outputs data structures.
*
*/
void free_outputs(void);
/* /*
* Returns the output with the given name * Returns the output with the given name
* *

View File

@ -106,7 +106,7 @@ __attribute__((format(printf, 1, 2))) static void set_statusline_error(const cha
va_list args; va_list args;
va_start(args, format); va_start(args, format);
if (vasprintf(&message, format, args) == -1) { if (vasprintf(&message, format, args) == -1) {
return; goto finish;
} }
struct status_block *err_block = scalloc(1, sizeof(struct status_block)); struct status_block *err_block = scalloc(1, sizeof(struct status_block));
@ -124,6 +124,7 @@ __attribute__((format(printf, 1, 2))) static void set_statusline_error(const cha
TAILQ_INSERT_HEAD(&statusline_head, err_block, blocks); TAILQ_INSERT_HEAD(&statusline_head, err_block, blocks);
TAILQ_INSERT_TAIL(&statusline_head, message_block, blocks); TAILQ_INSERT_TAIL(&statusline_head, message_block, blocks);
finish:
FREE(message); FREE(message);
va_end(args); va_end(args);
} }

View File

@ -192,6 +192,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
if (!strcmp(cur_key, "font")) { if (!strcmp(cur_key, "font")) {
DLOG("font = %.*s\n", len, val); DLOG("font = %.*s\n", len, val);
FREE(config.fontname);
sasprintf(&config.fontname, "%.*s", len, val); sasprintf(&config.fontname, "%.*s", len, val);
return 1; return 1;
} }

View File

@ -64,17 +64,14 @@ void got_subscribe_reply(char *reply) {
*/ */
void got_output_reply(char *reply) { void got_output_reply(char *reply) {
DLOG("Clearing old output configuration...\n"); DLOG("Clearing old output configuration...\n");
i3_output *o_walk; free_outputs();
SLIST_FOREACH(o_walk, outputs, slist) {
destroy_window(o_walk);
}
FREE_SLIST(outputs, i3_output);
DLOG("Parsing outputs JSON...\n"); DLOG("Parsing outputs JSON...\n");
parse_outputs_json(reply); parse_outputs_json(reply);
DLOG("Reconfiguring windows...\n"); DLOG("Reconfiguring windows...\n");
reconfig_windows(false); reconfig_windows(false);
i3_output *o_walk;
SLIST_FOREACH(o_walk, outputs, slist) { SLIST_FOREACH(o_walk, outputs, slist) {
kick_tray_clients(o_walk); kick_tray_clients(o_walk);
} }

View File

@ -182,7 +182,5 @@ int main(int argc, char **argv) {
clean_xcb(); clean_xcb();
ev_default_destroy(); ev_default_destroy();
free_workspaces();
return 0; return 0;
} }

View File

@ -173,6 +173,12 @@ static int outputs_start_map_cb(void *params_) {
return 1; 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) * 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) { if (!handle_output) {
DLOG("Ignoring output \"%s\", not configured to handle it.\n", DLOG("Ignoring output \"%s\", not configured to handle it.\n",
params->outputs_walk->name); params->outputs_walk->name);
FREE(params->outputs_walk->name); clear_output(params->outputs_walk);
FREE(params->outputs_walk->workspaces);
FREE(params->outputs_walk->trayclients);
FREE(params->outputs_walk); FREE(params->outputs_walk);
FREE(params->cur_key); FREE(params->cur_key);
return 1; return 1;
@ -217,6 +221,9 @@ static int outputs_end_map_cb(void *params_) {
target->primary = params->outputs_walk->primary; target->primary = params->outputs_walk->primary;
target->ws = params->outputs_walk->ws; target->ws = params->outputs_walk->ws;
target->rect = params->outputs_walk->rect; target->rect = params->outputs_walk->rect;
clear_output(params->outputs_walk);
FREE(params->outputs_walk);
} }
return 1; return 1;
} }
@ -260,7 +267,6 @@ void init_outputs(void) {
*/ */
void parse_outputs_json(char *json) { void parse_outputs_json(char *json) {
struct outputs_json_params params; struct outputs_json_params params;
params.outputs_walk = NULL; params.outputs_walk = NULL;
params.cur_key = NULL; params.cur_key = NULL;
params.json = json; params.json = json;
@ -286,6 +292,27 @@ void parse_outputs_json(char *json) {
yajl_free(handle); 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 * Returns the output with the given name
* *

View File

@ -1499,16 +1499,7 @@ void init_tray_colors(void) {
* *
*/ */
void clean_xcb(void) { void clean_xcb(void) {
i3_output *o_walk; free_outputs();
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_font(); free_font();