diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-12-15 18:03:59 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-12-15 19:01:41 -0500 |
commit | 8cef81d6f23adb66873ee5fd84aa7180b22624f2 (patch) | |
tree | 0739dff1b879b5a674dbd56e44ad4f4a44e941c7 | |
parent | Handle config-related allocation failures (diff) | |
download | sway-8cef81d6f23adb66873ee5fd84aa7180b22624f2.tar.gz sway-8cef81d6f23adb66873ee5fd84aa7180b22624f2.tar.zst sway-8cef81d6f23adb66873ee5fd84aa7180b22624f2.zip |
Handle some more memory allocation failures
-rw-r--r-- | sway/commands.c | 3 | ||||
-rw-r--r-- | sway/extensions.c | 4 | ||||
-rw-r--r-- | sway/handlers.c | 9 | ||||
-rw-r--r-- | sway/input.c | 4 | ||||
-rw-r--r-- | sway/ipc-server.c | 6 |
5 files changed, 25 insertions, 1 deletions
diff --git a/sway/commands.c b/sway/commands.c index dee03d71..8d199467 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -121,6 +121,9 @@ void input_cmd_apply(struct input_config *input) { | |||
121 | for (int i = 0; i < input_devices->length; ++i) { | 121 | for (int i = 0; i < input_devices->length; ++i) { |
122 | device = input_devices->items[i]; | 122 | device = input_devices->items[i]; |
123 | char* dev_identifier = libinput_dev_unique_id(device); | 123 | char* dev_identifier = libinput_dev_unique_id(device); |
124 | if (!dev_identifier) { | ||
125 | break; | ||
126 | } | ||
124 | int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0; | 127 | int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0; |
125 | free(dev_identifier); | 128 | free(dev_identifier); |
126 | if (match) { | 129 | if (match) { |
diff --git a/sway/extensions.c b/sway/extensions.c index 96c7e60d..759cbb84 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -81,6 +81,10 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc | |||
81 | } | 81 | } |
82 | sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output); | 82 | sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output); |
83 | struct background_config *config = malloc(sizeof(struct background_config)); | 83 | struct background_config *config = malloc(sizeof(struct background_config)); |
84 | if (!config) { | ||
85 | sway_log(L_ERROR, "Unable to allocate background config"); | ||
86 | return; | ||
87 | } | ||
84 | config->client = client; | 88 | config->client = client; |
85 | config->output = output; | 89 | config->output = output; |
86 | config->surface = wlc_resource_from_wl_surface_resource(surface); | 90 | config->surface = wlc_resource_from_wl_surface_resource(surface); |
diff --git a/sway/handlers.c b/sway/handlers.c index 23a994b4..3abe2fca 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -123,6 +123,11 @@ static void update_background_geometries(wlc_handle output) { | |||
123 | 123 | ||
124 | static bool handle_input_created(struct libinput_device *device) { | 124 | static bool handle_input_created(struct libinput_device *device) { |
125 | const char *identifier = libinput_dev_unique_id(device); | 125 | const char *identifier = libinput_dev_unique_id(device); |
126 | if (!identifier) { | ||
127 | sway_log(L_ERROR, "Unable to allocate unique name for input device %p", | ||
128 | device); | ||
129 | return true; | ||
130 | } | ||
126 | sway_log(L_INFO, "Found input device (%s)", identifier); | 131 | sway_log(L_INFO, "Found input device (%s)", identifier); |
127 | 132 | ||
128 | list_add(input_devices, device); | 133 | list_add(input_devices, device); |
@@ -402,6 +407,10 @@ static bool handle_view_created(wlc_handle handle) { | |||
402 | } else { | 407 | } else { |
403 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); | 408 | swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); |
404 | wlc_handle *h = malloc(sizeof(wlc_handle)); | 409 | wlc_handle *h = malloc(sizeof(wlc_handle)); |
410 | if (!h) { | ||
411 | sway_log(L_ERROR, "Unable to allocate window handle, view handler bailing out"); | ||
412 | return true; | ||
413 | } | ||
405 | *h = handle; | 414 | *h = handle; |
406 | sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged); | 415 | sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged); |
407 | list_add(output->unmanaged, h); | 416 | list_add(output->unmanaged, h); |
diff --git a/sway/input.c b/sway/input.c index acd69a6b..61757ab8 100644 --- a/sway/input.c +++ b/sway/input.c | |||
@@ -45,6 +45,10 @@ char *libinput_dev_unique_id(struct libinput_device *device) { | |||
45 | 45 | ||
46 | int len = strlen(name) + sizeof(char) * 6; | 46 | int len = strlen(name) + sizeof(char) * 6; |
47 | char *identifier = malloc(len); | 47 | char *identifier = malloc(len); |
48 | if (!identifier) { | ||
49 | sway_log(L_ERROR, "Unable to allocate unique input device name"); | ||
50 | return NULL; | ||
51 | } | ||
48 | 52 | ||
49 | const char *fmt = "%d:%d:%s"; | 53 | const char *fmt = "%d:%d:%s"; |
50 | snprintf(identifier, len, fmt, vendor, product, name); | 54 | snprintf(identifier, len, fmt, vendor, product, name); |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index de72beca..ba0cb310 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -414,7 +414,11 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
414 | struct libinput_device *device = input_devices->items[i]; | 414 | struct libinput_device *device = input_devices->items[i]; |
415 | char* identifier = libinput_dev_unique_id(device); | 415 | char* identifier = libinput_dev_unique_id(device); |
416 | json_object *device_object = json_object_new_object(); | 416 | json_object *device_object = json_object_new_object(); |
417 | json_object_object_add(device_object, "identifier", json_object_new_string(identifier)); | 417 | if (!identifier) { |
418 | json_object_object_add(device_object, "identifier", NULL); | ||
419 | } else { | ||
420 | json_object_object_add(device_object, "identifier", json_object_new_string(identifier)); | ||
421 | } | ||
418 | json_object_array_add(inputs, device_object); | 422 | json_object_array_add(inputs, device_object); |
419 | free(identifier); | 423 | free(identifier); |
420 | } | 424 | } |