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 | |
parent | 88a2ddbe83347c98dcd4bd20f6945e4923ea74ef (diff) |
commands: cmd_results->input is duplicated/freed.
-rw-r--r-- | include/commands.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 13 |
2 files changed, 11 insertions, 5 deletions
diff --git a/include/commands.h b/include/commands.h index 1e0a1452..8e53c74d 100644 --- a/include/commands.h +++ b/include/commands.h @@ -17,8 +17,7 @@ enum cmd_status { struct cmd_results { enum cmd_status status; - - const char *input; + char *input; char *error; }; 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) { if (results) { free_cmd_results(results); } - results = cmd_results_new(CMD_INVALID, strdup(cmd), "Unknown/invalid command"); + results = cmd_results_new(CMD_INVALID, cmd, "Unknown/invalid command"); free_argv(argc, argv); goto cleanup; } @@ -1291,7 +1291,7 @@ struct cmd_results *config_command(char *exec) { } struct cmd_handler *handler = find_handler(argv[0]); if (!handler) { - char *input = argv[0] ? strdup(argv[0]) : "(empty)"; + char *input = argv[0] ? argv[0] : "(empty)"; results = cmd_results_new(CMD_INVALID, input, "Unknown/invalid command"); goto cleanup; } @@ -1314,7 +1314,11 @@ struct cmd_results *config_command(char *exec) { struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { struct cmd_results *results = malloc(sizeof(struct cmd_results)); results->status = status; - results->input = input; // input is the command name + if (input) { + results->input = strdup(input); // input is the command name + } else { + results->input = NULL; + } if (format) { char *error = malloc(256); va_list args; @@ -1329,6 +1333,9 @@ struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, c } void free_cmd_results(struct cmd_results *results) { + if (results->input) { + free(results->input); + } if (results->error) { free(results->error); } |