From ffe9de6e24b451ba7885bc52c78fd676598bf7cd Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Wed, 4 Jul 2018 18:48:57 +0900 Subject: ipc-server: free clients at destroy --- sway/ipc-server.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sway/ipc-server.c') diff --git a/sway/ipc-server.c b/sway/ipc-server.c index abc2d7cb..01b80b05 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; -- cgit v1.2.3 From fe72e3b349f0905519481b77b22c525aca9c704d Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Thu, 5 Jul 2018 07:07:59 +0900 Subject: 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. --- sway/ipc-server.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sway/ipc-server.c') diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 01b80b05..96889b39 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; } -- cgit v1.2.3