summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-23 13:03:14 +0200
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-23 13:03:14 +0200
commit362413bd5031aa709ab5d7a39c0d5912554e545b (patch)
treec29db67ec97907448084a36909c1e51d74cd8eaf
parentcommands: Code formatting. (diff)
downloadsway-362413bd5031aa709ab5d7a39c0d5912554e545b.tar.gz
sway-362413bd5031aa709ab5d7a39c0d5912554e545b.tar.zst
sway-362413bd5031aa709ab5d7a39c0d5912554e545b.zip
commands: cmd_results->input is duplicated/freed.
-rw-r--r--include/commands.h3
-rw-r--r--sway/commands.c13
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 {
17 17
18struct cmd_results { 18struct cmd_results {
19 enum cmd_status status; 19 enum cmd_status status;
20 20 char *input;
21 const char *input;
22 char *error; 21 char *error;
23}; 22};
24 23
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) {
1314struct cmd_results *cmd_results_new(enum cmd_status status, const char* input, const char *format, ...) { 1314struct 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
1331void free_cmd_results(struct cmd_results *results) { 1335void 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 }