Handle allocation failure in commands

This commit is contained in:
Drew DeVault 2016-12-15 17:39:09 -05:00
parent 8691ff1b63
commit 248df18c24
11 changed files with 78 additions and 16 deletions

View file

@ -30,7 +30,10 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
}
// Create mode if it doesn't exist
if (!mode && mode_make) {
mode = malloc(sizeof*mode);
mode = malloc(sizeof(struct sway_mode));
if (!mode) {
return cmd_results_new(CMD_FAILURE, "mode", "Unable to allocate mode");
}
mode->name = strdup(mode_name);
mode->bindings = create_list();
list_add(config->modes, mode);