compositor: create_data_source(): Fix potential crash on OOM

Noticed this while working on primary selection, in the event we run out
of memory when trying to create a new data source, there's a chance
we'll fail on wl_resource_create() and crash from source->resource being
set to NULL.

Signed-off-by: Lyude <cpaul@redhat.com>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
dev
cpaul@redhat.com 9 years ago committed by Bryce Harrington
parent 89324ce888
commit c9f8f8a7f4
  1. 10
      src/data-device.c

@ -881,6 +881,14 @@ create_data_source(struct wl_client *client,
return; return;
} }
source->resource =
wl_resource_create(client, &wl_data_source_interface, 1, id);
if (source->resource == NULL) {
free(source);
wl_resource_post_no_memory(resource);
return;
}
wl_signal_init(&source->destroy_signal); wl_signal_init(&source->destroy_signal);
source->accept = client_source_accept; source->accept = client_source_accept;
source->send = client_source_send; source->send = client_source_send;
@ -888,8 +896,6 @@ create_data_source(struct wl_client *client,
wl_array_init(&source->mime_types); wl_array_init(&source->mime_types);
source->resource =
wl_resource_create(client, &wl_data_source_interface, 1, id);
wl_resource_set_implementation(source->resource, &data_source_interface, wl_resource_set_implementation(source->resource, &data_source_interface,
source, destroy_data_source); source, destroy_data_source);
} }

Loading…
Cancel
Save