mirror of
https://github.com/swaywm/sway.git
synced 2025-11-05 13:29:51 -05:00
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.
This commit is contained in:
parent
9314c45c41
commit
fe72e3b349
3 changed files with 8 additions and 9 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue