diff options
author | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-23 13:03:14 +0200 |
---|---|---|
committer | S. Christoffer Eliesen <christoffer@eliesen.no> | 2015-10-23 13:03:14 +0200 |
commit | 362413bd5031aa709ab5d7a39c0d5912554e545b (patch) | |
tree | c29db67ec97907448084a36909c1e51d74cd8eaf /sway | |
parent | commands: Code formatting. (diff) | |
download | sway-362413bd5031aa709ab5d7a39c0d5912554e545b.tar.gz sway-362413bd5031aa709ab5d7a39c0d5912554e545b.tar.zst sway-362413bd5031aa709ab5d7a39c0d5912554e545b.zip |
commands: cmd_results->input is duplicated/freed.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/sway/commands.c b/sway/commands.c index d742495d..8c45dabe 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -1249,7 +1249,7 @@ struct cmd_results *handle_command(char *_exec) { | |||
1249 | if (results) { | 1249 | if (results) { |
1250 | free_cmd_results(results); | 1250 | free_cmd_results(results); |
1251 | } | 1251 | } |
1252 | results = cmd_results_new(CMD_INVALID, strdup(cmd), "Unknown/invalid command"); | 1252 | results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command"); |
1253 | free_argv(argc, argv); | 1253 | free_argv(argc, argv); |
1254 | goto cleanup; | 1254 | goto cleanup; |
1255 | } | 1255 | } |
@@ -1291,7 +1291,7 @@ struct cmd_results *config_command(char *exec) { | |||
1291 | } | 1291 | } |
1292 | struct cmd_handler *handler = find_handler(argv[0]); | 1292 | struct cmd_handler *handler = find_handler(argv[0]); |
1293 | if (!handler) { | 1293 | if (!handler) { |
1294 | char *input = argv[0] ? strdup(argv[0]) : "(empty)"; | 1294 | char *input = argv[0] ? argv[0] : "(empty)"; |
1295 | results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); | 1295 | results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); |
1296 | goto cleanup; | 1296 | goto cleanup; |
1297 | } | 1297 | } |
@@ -1314,7 +1314,11 @@ struct cmd_results *config_command(char *exec) { | |||
1314 | struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { | 1314 | struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { |
1315 | struct cmd_results *results = malloc(sizeof(struct cmd_results)); | 1315 | struct cmd_results *results = malloc(sizeof(struct cmd_results)); |
1316 | results->status = status; | 1316 | results->status = status; |
1317 | results->input = input; // input is the command name | 1317 | if (input) { |
1318 | results->input = strdup(input); // input is the command name | ||
1319 | } else { | ||
1320 | results->input = NULL; | ||
1321 | } | ||
1318 | if (format) { | 1322 | if (format) { |
1319 | char *error = malloc(256); | 1323 | char *error = malloc(256); |
1320 | va_list args; | 1324 | va_list args; |
@@ -1329,6 +1333,9 @@ struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, c | |||
1329 | } | 1333 | } |
1330 | 1334 | ||
1331 | void free_cmd_results(struct cmd_results *results) { | 1335 | void free_cmd_results(struct cmd_results *results) { |
1336 | if (results->input) { | ||
1337 | free(results->input); | ||
1338 | } | ||
1332 | if (results->error) { | 1339 | if (results->error) { |
1333 | free(results->error); | 1340 | free(results->error); |
1334 | } | 1341 | } |