diff options
-rw-r--r-- | sway/commands.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sway/commands.c b/sway/commands.c index 50a6e941..d742495d 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1329,19 +1329,21 @@ struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, c | |||
1329 | } | 1329 | } |
1330 | 1330 | ||
1331 | void free_cmd_results(struct cmd_results *results) { | 1331 | void free_cmd_results(struct cmd_results *results) { |
1332 | if (results->error) | 1332 | if (results->error) { |
1333 | free(results->error); | 1333 | free(results->error); |
1334 | } | ||
1334 | free(results); | 1335 | free(results); |
1335 | } | 1336 | } |
1336 | 1337 | ||
1337 | const char *cmd_results_to_json(struct cmd_results *results) { | 1338 | const char *cmd_results_to_json(struct cmd_results *results) { |
1338 | json_object *root = json_object_new_object(); | 1339 | json_object *root = json_object_new_object(); |
1339 | json_object_object_add(root, "success", json_object_new_boolean(results->status == CMD_SUCCESS)); | 1340 | json_object_object_add(root, "success", json_object_new_boolean(results->status == CMD_SUCCESS)); |
1340 | if (results->input) | 1341 | if (results->input) { |
1341 | json_object_object_add(root, "input", json_object_new_string(results->input)); | 1342 | json_object_object_add(root, "input", json_object_new_string(results->input)); |
1342 | if (results->error) | 1343 | } |
1344 | if (results->error) { | ||
1343 | json_object_object_add(root, "error", json_object_new_string(results->error)); | 1345 | json_object_object_add(root, "error", json_object_new_string(results->error)); |
1344 | 1346 | } | |
1345 | const char *json = json_object_to_json_string(root); | 1347 | const char *json = json_object_to_json_string(root); |
1346 | free(root); | 1348 | free(root); |
1347 | return json; | 1349 | return json; |