Handle some more memory allocation failures

master
Drew DeVault 8 years ago
parent d75a747a3d
commit 8cef81d6f2

@ -121,6 +121,9 @@ void input_cmd_apply(struct input_config *input) {
for (int i = 0; i < input_devices->length; ++i) {
device = input_devices->items[i];
char* dev_identifier = libinput_dev_unique_id(device);
if (!dev_identifier) {
break;
}
int match = dev_identifier && strcmp(dev_identifier, input->identifier) == 0;
free(dev_identifier);
if (match) {

@ -81,6 +81,10 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc
}
sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output);
struct background_config *config = malloc(sizeof(struct background_config));
if (!config) {
sway_log(L_ERROR, "Unable to allocate background config");
return;
}
config->client = client;
config->output = output;
config->surface = wlc_resource_from_wl_surface_resource(surface);

@ -123,6 +123,11 @@ static void update_background_geometries(wlc_handle output) {
static bool handle_input_created(struct libinput_device *device) {
const char *identifier = libinput_dev_unique_id(device);
if (!identifier) {
sway_log(L_ERROR, "Unable to allocate unique name for input device %p",
device);
return true;
}
sway_log(L_INFO, "Found input device (%s)", identifier);
list_add(input_devices, device);
@ -402,6 +407,10 @@ static bool handle_view_created(wlc_handle handle) {
} else {
swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
wlc_handle *h = malloc(sizeof(wlc_handle));
if (!h) {
sway_log(L_ERROR, "Unable to allocate window handle, view handler bailing out");
return true;
}
*h = handle;
sway_log(L_DEBUG, "Adding unmanaged window %p to %p", h, output->unmanaged);
list_add(output->unmanaged, h);

@ -45,6 +45,10 @@ char *libinput_dev_unique_id(struct libinput_device *device) {
int len = strlen(name) + sizeof(char) * 6;
char *identifier = malloc(len);
if (!identifier) {
sway_log(L_ERROR, "Unable to allocate unique input device name");
return NULL;
}
const char *fmt = "%d:%d:%s";
snprintf(identifier, len, fmt, vendor, product, name);

@ -414,7 +414,11 @@ void ipc_client_handle_command(struct ipc_client *client) {
struct libinput_device *device = input_devices->items[i];
char* identifier = libinput_dev_unique_id(device);
json_object *device_object = json_object_new_object();
json_object_object_add(device_object, "identifier", json_object_new_string(identifier));
if (!identifier) {
json_object_object_add(device_object, "identifier", NULL);
} else {
json_object_object_add(device_object, "identifier", json_object_new_string(identifier));
}
json_object_array_add(inputs, device_object);
free(identifier);
}

Loading…
Cancel
Save