diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-12-15 18:26:53 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-12-15 19:01:41 -0500 |
commit | 10c8b73075fa0dd5512cc14be7240ec47f68dece (patch) | |
tree | e8835ef640d1d21ce0f36a5b1bcee726d926e55e /sway/commands | |
parent | Add remaining sway allocation failure handling (diff) | |
download | sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.tar.gz sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.tar.zst sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.zip |
Handle calloc failures
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/assign.c | 5 | ||||
-rw-r--r-- | sway/commands/output.c | 3 | ||||
-rw-r--r-- | sway/commands/workspace.c | 4 |
3 files changed, 11 insertions, 1 deletions
diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 1824692b..992b4692 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c | |||
@@ -23,11 +23,14 @@ struct cmd_results *cmd_assign(int argc, char **argv) { | |||
23 | char *movecmd = "move container to workspace "; | 23 | char *movecmd = "move container to workspace "; |
24 | int arglen = strlen(movecmd) + strlen(*argv) + 1; | 24 | int arglen = strlen(movecmd) + strlen(*argv) + 1; |
25 | char *cmdlist = calloc(1, arglen); | 25 | char *cmdlist = calloc(1, arglen); |
26 | 26 | if (!cmdlist) { | |
27 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list"); | ||
28 | } | ||
27 | snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); | 29 | snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); |
28 | 30 | ||
29 | struct criteria *crit = malloc(sizeof(struct criteria)); | 31 | struct criteria *crit = malloc(sizeof(struct criteria)); |
30 | if (!crit) { | 32 | if (!crit) { |
33 | free(cmdlist); | ||
31 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria"); | 34 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria"); |
32 | } | 35 | } |
33 | crit->crit_raw = strdup(criteria); | 36 | crit->crit_raw = strdup(criteria); |
diff --git a/sway/commands/output.c b/sway/commands/output.c index e150aed2..01ac9f4e 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -26,6 +26,9 @@ struct cmd_results *cmd_output(int argc, char **argv) { | |||
26 | const char *name = argv[0]; | 26 | const char *name = argv[0]; |
27 | 27 | ||
28 | struct output_config *output = calloc(1, sizeof(struct output_config)); | 28 | struct output_config *output = calloc(1, sizeof(struct output_config)); |
29 | if (!output) { | ||
30 | return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); | ||
31 | } | ||
29 | output->x = output->y = output->width = output->height = -1; | 32 | output->x = output->y = output->width = output->height = -1; |
30 | output->name = strdup(name); | 33 | output->name = strdup(name); |
31 | output->enabled = -1; | 34 | output->enabled = -1; |
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 35224f8a..14fe242f 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -61,6 +61,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
61 | return error; | 61 | return error; |
62 | } | 62 | } |
63 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); | 63 | struct workspace_output *wso = calloc(1, sizeof(struct workspace_output)); |
64 | if (!wso) { | ||
65 | return cmd_results_new(CMD_FAILURE, "workspace output", | ||
66 | "Unable to allocate workspace output"); | ||
67 | } | ||
64 | wso->workspace = strdup(argv[0]); | 68 | wso->workspace = strdup(argv[0]); |
65 | wso->output = strdup(argv[2]); | 69 | wso->output = strdup(argv[2]); |
66 | int i = -1; | 70 | int i = -1; |