diff options
| author | Dominique Martinet <[email protected]> | 2018-07-05 07:07:59 +0900 | 
|---|---|---|
| committer | Dominique Martinet <[email protected]> | 2018-07-05 13:11:02 +0900 | 
| commit | fe72e3b349f0905519481b77b22c525aca9c704d (patch) | |
| tree | 3b63d204bf5b1fef09814d45786030c46a317b86 /sway/commands.c | |
| parent | 9314c45c418c97fa415ef86cf834c3c87499d100 (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/commands.c')
| -rw-r--r-- | sway/commands.c | 8 | 
1 files changed, 4 insertions, 4 deletions
| diff --git a/sway/commands.c b/sway/commands.c index 5b67e1ec..ef477f38 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;  }  /** | 
