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 | |
parent | Add remaining sway allocation failure handling (diff) | |
download | sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.tar.gz sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.tar.zst sway-10c8b73075fa0dd5512cc14be7240ec47f68dece.zip |
Handle calloc failures
-rw-r--r-- | sway/commands/assign.c | 5 | ||||
-rw-r--r-- | sway/commands/output.c | 3 | ||||
-rw-r--r-- | sway/commands/workspace.c | 4 | ||||
-rw-r--r-- | sway/config.c | 3 | ||||
-rw-r--r-- | sway/container.c | 3 | ||||
-rw-r--r-- | sway/extensions.c | 4 | ||||
-rw-r--r-- | sway/input.c | 10 | ||||
-rw-r--r-- | sway/ipc-json.c | 9 |
8 files changed, 39 insertions, 2 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; |
diff --git a/sway/config.c b/sway/config.c index b86bacdb..4164cefa 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -494,6 +494,9 @@ bool load_main_config(const char *file, bool is_active) { | |||
494 | 494 | ||
495 | struct sway_config *old_config = config; | 495 | struct sway_config *old_config = config; |
496 | config = calloc(1, sizeof(struct sway_config)); | 496 | config = calloc(1, sizeof(struct sway_config)); |
497 | if (!config) { | ||
498 | sway_abort("Unable to allocate config"); | ||
499 | } | ||
497 | 500 | ||
498 | config_defaults(config); | 501 | config_defaults(config); |
499 | if (is_active) { | 502 | if (is_active) { |
diff --git a/sway/container.c b/sway/container.c index 8a584efa..d9677cdb 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -23,6 +23,9 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
23 | // next id starts at 1 because 0 is assigned to root_container in layout.c | 23 | // next id starts at 1 because 0 is assigned to root_container in layout.c |
24 | static size_t next_id = 1; | 24 | static size_t next_id = 1; |
25 | swayc_t *c = calloc(1, sizeof(swayc_t)); | 25 | swayc_t *c = calloc(1, sizeof(swayc_t)); |
26 | if (!c) { | ||
27 | return NULL; | ||
28 | } | ||
26 | c->id = next_id++; | 29 | c->id = next_id++; |
27 | c->handle = -1; | 30 | c->handle = -1; |
28 | c->gaps = -1; | 31 | c->gaps = -1; |
diff --git a/sway/extensions.c b/sway/extensions.c index 759cbb84..40702e28 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -23,6 +23,10 @@ static struct panel_config *find_or_create_panel_config(struct wl_resource *reso | |||
23 | } | 23 | } |
24 | sway_log(L_DEBUG, "Creating panel config for resource %p", resource); | 24 | sway_log(L_DEBUG, "Creating panel config for resource %p", resource); |
25 | struct panel_config *config = calloc(1, sizeof(struct panel_config)); | 25 | struct panel_config *config = calloc(1, sizeof(struct panel_config)); |
26 | if (!config) { | ||
27 | sway_log(L_ERROR, "Unable to create panel config"); | ||
28 | return NULL; | ||
29 | } | ||
26 | list_add(desktop_shell.panels, config); | 30 | list_add(desktop_shell.panels, config); |
27 | config->wl_resource = resource; | 31 | config->wl_resource = resource; |
28 | return config; | 32 | return config; |
diff --git a/sway/input.c b/sway/input.c index 61757ab8..249d95c6 100644 --- a/sway/input.c +++ b/sway/input.c | |||
@@ -11,8 +11,16 @@ | |||
11 | 11 | ||
12 | struct input_config *new_input_config(const char* identifier) { | 12 | struct input_config *new_input_config(const char* identifier) { |
13 | struct input_config *input = calloc(1, sizeof(struct input_config)); | 13 | struct input_config *input = calloc(1, sizeof(struct input_config)); |
14 | if (!input) { | ||
15 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
16 | return NULL; | ||
17 | } | ||
14 | sway_log(L_DEBUG, "new_input_config(%s)", identifier); | 18 | sway_log(L_DEBUG, "new_input_config(%s)", identifier); |
15 | input->identifier = strdup(identifier); | 19 | if (!(input->identifier = strdup(identifier))) { |
20 | free(input); | ||
21 | sway_log(L_DEBUG, "Unable to allocate input config"); | ||
22 | return NULL; | ||
23 | } | ||
16 | 24 | ||
17 | input->tap = INT_MIN; | 25 | input->tap = INT_MIN; |
18 | input->drag_lock = INT_MIN; | 26 | input->drag_lock = INT_MIN; |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index e65e9de3..fd17216e 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -245,6 +245,15 @@ json_object *ipc_json_get_version() { | |||
245 | 245 | ||
246 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | 246 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE |
247 | char *full_version = calloc(strlen(SWAY_GIT_VERSION) + strlen(SWAY_GIT_BRANCH) + strlen(SWAY_VERSION_DATE) + 20, 1); | 247 | char *full_version = calloc(strlen(SWAY_GIT_VERSION) + strlen(SWAY_GIT_BRANCH) + strlen(SWAY_VERSION_DATE) + 20, 1); |
248 | if (!full_version) { | ||
249 | json_object_object_add(version, "human_readable", | ||
250 | json_object_new_string("Allocating version string failed")); | ||
251 | // TODO: it's stupid that we allocate this in the first place | ||
252 | json_object_object_add(version, "major", json_object_new_int(0)); | ||
253 | json_object_object_add(version, "minor", json_object_new_int(0)); | ||
254 | json_object_object_add(version, "patch", json_object_new_int(0)); | ||
255 | return version; | ||
256 | } | ||
248 | strcat(full_version, SWAY_GIT_VERSION); | 257 | strcat(full_version, SWAY_GIT_VERSION); |
249 | strcat(full_version, " ("); | 258 | strcat(full_version, " ("); |
250 | strcat(full_version, SWAY_VERSION_DATE); | 259 | strcat(full_version, SWAY_VERSION_DATE); |