From 8a771785ad9026b12f0b23e89c69cafecbc3b752 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 15:10:23 +0900 Subject: [PATCH 1/8] keyboard: free xkb keymap on destroy --- sway/input/keyboard.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index ec149d060..182536de1 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c @@ -420,6 +420,9 @@ void sway_keyboard_destroy(struct sway_keyboard *keyboard) { if (!keyboard) { return; } + if (keyboard->keymap) { + xkb_keymap_unref(keyboard->keymap); + } wl_list_remove(&keyboard->keyboard_key.link); wl_list_remove(&keyboard->keyboard_modifiers.link); free(keyboard); From 9f5d5396579e0029c8841992ca39e850281a2df6 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:43:35 +0900 Subject: [PATCH 2/8] config: add a couple of forgotten frees --- sway/config.c | 7 ++++++- sway/config/bar.c | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 0aae16961..89b7d349a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -87,7 +87,12 @@ void free_config(struct sway_config *config) { list_free(config->cmd_queue); list_free(config->workspace_outputs); list_free(config->pid_workspaces); - list_free(config->output_configs); + if (config->output_configs) { + for (int i = 0; i < config->output_configs->length; i++) { + free_output_config(config->output_configs->items[i]); + } + list_free(config->output_configs); + } if (config->input_configs) { for (int i = 0; i < config->input_configs->length; i++) { free_input_config(config->input_configs->items[i]); diff --git a/sway/config/bar.c b/sway/config/bar.c index b97076a02..ee062c6a5 100644 --- a/sway/config/bar.c +++ b/sway/config/bar.c @@ -30,6 +30,7 @@ void free_bar_config(struct bar_config *bar) { if (!bar) { return; } + free(bar->id); free(bar->mode); free(bar->position); free(bar->hidden_state); From ffe9de6e24b451ba7885bc52c78fd676598bf7cd Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:48:57 +0900 Subject: [PATCH 3/8] ipc-server: free clients at destroy --- sway/ipc-server.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index abc2d7cba..01b80b05e 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -64,6 +64,10 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { close(ipc_socket); unlink(ipc_sockaddr->sun_path); + while (ipc_client_list->length) { + struct ipc_client *client = ipc_client_list->items[0]; + ipc_client_disconnect(client); + } list_free(ipc_client_list); if (ipc_sockaddr) { @@ -480,6 +484,7 @@ void ipc_client_handle_command(struct ipc_client *client) { const char *json = cmd_results_to_json(results); char reply[256]; int length = snprintf(reply, sizeof(reply), "%s", json); + free(json); client_valid = ipc_send_reply(client, reply, (uint32_t)length); free_cmd_results(results); goto exit_cleanup; From ffbe91c245ae09bc94f31556cb4104c5957aacef Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:50:13 +0900 Subject: [PATCH 4/8] container_free: free formatted title --- sway/tree/container.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/tree/container.c b/sway/tree/container.c index 3614d4e73..9093feba9 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -151,6 +151,7 @@ void container_free(struct sway_container *cont) { return; } free(cont->name); + free(cont->formatted_title); wlr_texture_destroy(cont->title_focused); wlr_texture_destroy(cont->title_focused_inactive); wlr_texture_destroy(cont->title_unfocused); From 785ed4383be2c781748c9f60e2d6460200a1abeb Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:50:31 +0900 Subject: [PATCH 5/8] view_map: free criterias as the list it is --- sway/tree/view.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 6b4daa820..bca8ef8a6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -514,7 +514,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { if (container_is_floating(focus)) { focus = focus->parent->parent; } - free(criterias); + list_free(criterias); cont = container_view_create(focus, view); view->surface = wlr_surface; From 9314c45c418c97fa415ef86cf834c3c87499d100 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:51:21 +0900 Subject: [PATCH 6/8] workspace_next_name: free targets later than these already found in order --- sway/tree/workspace.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 2db06a318..51f0fcb40 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -191,6 +191,8 @@ char *workspace_next_name(const char *output_name) { free(target); target = _target; wlr_log(L_DEBUG, "Workspace: Found free name %s", _target); + } else { + free(_target); } } free(dup); From fe72e3b349f0905519481b77b22c525aca9c704d Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 5 Jul 2018 07:07:59 +0900 Subject: [PATCH 7/8] cmd_results_to_json: return copied string and properly free the json The only user of this function would copy the string right away to get rid of the const flag anyway, and freeing a const string afterwards might work but is not meant to be done according to the json-c API. --- include/sway/commands.h | 2 +- sway/commands.c | 8 ++++---- sway/ipc-server.c | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/sway/commands.h b/include/sway/commands.h index 7ca0bda88..6d17144a9 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -79,7 +79,7 @@ void free_cmd_results(struct cmd_results *results); * * Free the JSON string later on. */ -const char *cmd_results_to_json(struct cmd_results *results); +char *cmd_results_to_json(struct cmd_results *results); struct cmd_results *add_color(const char *name, char *buffer, const char *color); diff --git a/sway/commands.c b/sway/commands.c index 5b67e1ec5..ef477f389 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -527,7 +527,7 @@ void free_cmd_results(struct cmd_results *results) { free(results); } -const char *cmd_results_to_json(struct cmd_results *results) { +char *cmd_results_to_json(struct cmd_results *results) { json_object *result_array = json_object_new_array(); json_object *root = json_object_new_object(); json_object_object_add(root, "success", @@ -542,9 +542,9 @@ const char *cmd_results_to_json(struct cmd_results *results) { } json_object_array_add(result_array, root); const char *json = json_object_to_json_string(result_array); - free(result_array); - free(root); - return json; + char *res = strdup(json); + json_object_put(result_array); + return res; } /** diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 01b80b05e..96889b395 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -481,11 +481,10 @@ void ipc_client_handle_command(struct ipc_client *client) { case IPC_COMMAND: { struct cmd_results *results = execute_command(buf, NULL); - const char *json = cmd_results_to_json(results); - char reply[256]; - int length = snprintf(reply, sizeof(reply), "%s", json); + char *json = cmd_results_to_json(results); + int length = strlen(json); + client_valid = ipc_send_reply(client, json, (uint32_t)length); free(json); - client_valid = ipc_send_reply(client, reply, (uint32_t)length); free_cmd_results(results); goto exit_cleanup; } From 7ef08ffbe6dc9a0b35cd9cad0b689136e3515886 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 5 Jul 2018 08:01:09 +0900 Subject: [PATCH 8/8] pango/cairo: set default font map to NULL to free it --- sway/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sway/main.c b/sway/main.c index 96e41bbcb..ec7353be7 100644 --- a/sway/main.c +++ b/sway/main.c @@ -1,6 +1,7 @@ #define _XOPEN_SOURCE 700 #define _POSIX_C_SOURCE 200112L #include +#include #include #include #include @@ -441,5 +442,7 @@ int main(int argc, char **argv) { free_config(config); } + pango_cairo_font_map_set_default(NULL); + return exit_value; }