summaryrefslogtreecommitdiff
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorDominique Martinet <[email protected]>2018-07-05 07:07:59 +0900
committerDominique Martinet <[email protected]>2018-07-05 13:11:02 +0900
commitfe72e3b349f0905519481b77b22c525aca9c704d (patch)
tree3b63d204bf5b1fef09814d45786030c46a317b86 /sway/ipc-server.c
parent9314c45c418c97fa415ef86cf834c3c87499d100 (diff)
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.
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c7
1 files changed, 3 insertions, 4 deletions
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;
}