Add checks for wl_resource_create

This commit is contained in:
emersion 2017-11-02 23:14:24 +01:00
parent 80b4a2f64c
commit f8de7aa0fd
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
10 changed files with 154 additions and 63 deletions

View file

@ -13,10 +13,21 @@ static void destroy_surface_listener(struct wl_listener *listener, void *data) {
static void wl_compositor_create_surface(struct wl_client *client, static void wl_compositor_create_surface(struct wl_client *client,
struct wl_resource *resource, uint32_t id) { struct wl_resource *resource, uint32_t id) {
struct wlr_compositor *compositor = wl_resource_get_user_data(resource); struct wlr_compositor *compositor = wl_resource_get_user_data(resource);
struct wl_resource *surface_resource = wl_resource_create(client, struct wl_resource *surface_resource = wl_resource_create(client,
&wl_surface_interface, wl_resource_get_version(resource), id); &wl_surface_interface, wl_resource_get_version(resource), id);
if (surface_resource == NULL) {
wl_resource_post_no_memory(resource);
return;
}
struct wlr_surface *surface = wlr_surface_create(surface_resource, struct wlr_surface *surface = wlr_surface_create(surface_resource,
compositor->renderer); compositor->renderer);
if (surface == NULL) {
wl_resource_destroy(surface_resource);
wl_resource_post_no_memory(resource);
return;
}
surface->compositor_data = compositor; surface->compositor_data = compositor;
surface->compositor_listener.notify = &destroy_surface_listener; surface->compositor_listener.notify = &destroy_surface_listener;
wl_resource_add_destroy_listener(surface_resource, wl_resource_add_destroy_listener(surface_resource,
@ -49,13 +60,17 @@ static void wl_compositor_destroy(struct wl_resource *resource) {
} }
} }
static void wl_compositor_bind(struct wl_client *wl_client, void *_compositor, static void wl_compositor_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_compositor *compositor = _compositor; struct wlr_compositor *compositor = data;
assert(wl_client && compositor); assert(wl_client && compositor);
struct wl_resource *wl_resource = struct wl_resource *wl_resource =
wl_resource_create(wl_client, &wl_compositor_interface, version, id); wl_resource_create(wl_client, &wl_compositor_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &wl_compositor_impl, wl_resource_set_implementation(wl_resource, &wl_compositor_impl,
compositor, wl_compositor_destroy); compositor, wl_compositor_destroy);
wl_list_insert(&compositor->wl_resources, wl_list_insert(&compositor->wl_resources,

View file

@ -233,6 +233,9 @@ static struct wlr_data_offer *wlr_data_source_send_offer(
struct wlr_data_source *source, struct wlr_data_source *source,
struct wl_resource *target) { struct wl_resource *target) {
struct wlr_data_offer *offer = calloc(1, sizeof(struct wlr_data_offer)); struct wlr_data_offer *offer = calloc(1, sizeof(struct wlr_data_offer));
if (offer == NULL) {
return NULL;
}
offer->resource = offer->resource =
wl_resource_create(wl_resource_get_client(target), wl_resource_create(wl_resource_get_client(target),
@ -781,9 +784,7 @@ data_device_manager_impl = {
static void data_device_manager_bind(struct wl_client *client, static void data_device_manager_bind(struct wl_client *client,
void *data, uint32_t version, uint32_t id) { void *data, uint32_t version, uint32_t id) {
struct wl_resource *resource; struct wl_resource *resource = wl_resource_create(client,
resource = wl_resource_create(client,
&wl_data_device_manager_interface, &wl_data_device_manager_interface,
version, id); version, id);
if (resource == NULL) { if (resource == NULL) {
@ -791,8 +792,8 @@ static void data_device_manager_bind(struct wl_client *client,
return; return;
} }
wl_resource_set_implementation(resource, wl_resource_set_implementation(resource, &data_device_manager_impl,
&data_device_manager_impl, NULL, NULL); NULL, NULL);
} }
struct wlr_data_device_manager *wlr_data_device_manager_create( struct wlr_data_device_manager *wlr_data_device_manager_create(
@ -807,7 +808,6 @@ struct wlr_data_device_manager *wlr_data_device_manager_create(
manager->global = manager->global =
wl_global_create(display, &wl_data_device_manager_interface, wl_global_create(display, &wl_data_device_manager_interface,
3, NULL, data_device_manager_bind); 3, NULL, data_device_manager_bind);
if (!manager->global) { if (!manager->global) {
wlr_log(L_ERROR, "could not create data device manager wl global"); wlr_log(L_ERROR, "could not create data device manager wl global");
free(manager); free(manager);

View file

@ -83,8 +83,8 @@ static void gamma_control_manager_get_gamma_control(struct wl_client *client,
gamma_control->resource = wl_resource_create(client, gamma_control->resource = wl_resource_create(client,
&gamma_control_interface, version, id); &gamma_control_interface, version, id);
if (gamma_control->resource == NULL) { if (gamma_control->resource == NULL) {
wl_client_post_no_memory(client);
free(gamma_control); free(gamma_control);
wl_client_post_no_memory(client);
return; return;
} }
wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control, wlr_log(L_DEBUG, "new gamma_control %p (res %p)", gamma_control,
@ -109,10 +109,9 @@ static struct gamma_control_manager_interface gamma_control_manager_impl = {
.get_gamma_control = gamma_control_manager_get_gamma_control, .get_gamma_control = gamma_control_manager_get_gamma_control,
}; };
static void gamma_control_manager_bind(struct wl_client *client, static void gamma_control_manager_bind(struct wl_client *client, void *data,
void *_gamma_control_manager, uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_gamma_control_manager *gamma_control_manager = struct wlr_gamma_control_manager *gamma_control_manager = data;
_gamma_control_manager;
assert(client && gamma_control_manager); assert(client && gamma_control_manager);
struct wl_resource *resource = wl_resource_create(client, struct wl_resource *resource = wl_resource_create(client,

View file

@ -91,13 +91,17 @@ static struct wl_output_interface wl_output_impl = {
.release = wl_output_release .release = wl_output_release
}; };
static void wl_output_bind(struct wl_client *wl_client, void *_wlr_output, static void wl_output_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_output *wlr_output = _wlr_output; struct wlr_output *wlr_output = data;
assert(wl_client && wlr_output); assert(wl_client && wlr_output);
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&wl_output_interface, version, id); &wl_output_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output, wl_resource_set_implementation(wl_resource, &wl_output_impl, wlr_output,
wl_output_destroy); wl_output_destroy);
wl_list_insert(&wlr_output->wl_resources, wl_list_insert(&wlr_output->wl_resources,

View file

@ -51,16 +51,17 @@ static void output_frame_notify(struct wl_listener *listener, void *_data) {
} }
static void screenshooter_shoot(struct wl_client *client, static void screenshooter_shoot(struct wl_client *client,
struct wl_resource *_screenshooter, uint32_t id, struct wl_resource *screenshooter_resource, uint32_t id,
struct wl_resource *_output, struct wl_resource *_buffer) { struct wl_resource *output_resource,
struct wl_resource *buffer_resource) {
struct wlr_screenshooter *screenshooter = struct wlr_screenshooter *screenshooter =
wl_resource_get_user_data(_screenshooter); wl_resource_get_user_data(screenshooter_resource);
struct wlr_output *output = wl_resource_get_user_data(_output); struct wlr_output *output = wl_resource_get_user_data(output_resource);
if (!wl_shm_buffer_get(_buffer)) { if (!wl_shm_buffer_get(buffer_resource)) {
wlr_log(L_ERROR, "Invalid buffer: not a shared memory buffer"); wlr_log(L_ERROR, "Invalid buffer: not a shared memory buffer");
return; return;
} }
struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(_buffer); struct wl_shm_buffer *shm_buffer = wl_shm_buffer_get(buffer_resource);
int32_t width = wl_shm_buffer_get_width(shm_buffer); int32_t width = wl_shm_buffer_get_width(shm_buffer);
int32_t height = wl_shm_buffer_get_height(shm_buffer); int32_t height = wl_shm_buffer_get_height(shm_buffer);
int32_t stride = wl_shm_buffer_get_stride(shm_buffer); int32_t stride = wl_shm_buffer_get_stride(shm_buffer);
@ -84,23 +85,31 @@ static void screenshooter_shoot(struct wl_client *client,
struct wlr_screenshot *screenshot = struct wlr_screenshot *screenshot =
calloc(1, sizeof(struct wlr_screenshot)); calloc(1, sizeof(struct wlr_screenshot));
if (!screenshot) { if (!screenshot) {
wl_client_post_no_memory(client); wl_resource_post_no_memory(screenshooter_resource);
return; return;
} }
screenshot->output_resource = _output; screenshot->output_resource = output_resource;
screenshot->output = output; screenshot->output = output;
screenshot->screenshooter = screenshooter; screenshot->screenshooter = screenshooter;
screenshot->resource = wl_resource_create(client, screenshot->resource = wl_resource_create(client,
&orbital_screenshot_interface, wl_resource_get_version(_screenshooter), &orbital_screenshot_interface,
id); wl_resource_get_version(screenshooter_resource), id);
wlr_log(L_DEBUG, "new screenshot %p (res %p)", screenshot, if (screenshot->resource == NULL) {
screenshot->resource); free(screenshot);
wl_resource_post_no_memory(screenshooter_resource);
return;
}
wl_resource_set_implementation(screenshot->resource, NULL, screenshot, wl_resource_set_implementation(screenshot->resource, NULL, screenshot,
NULL); NULL);
wlr_log(L_DEBUG, "new screenshot %p (res %p)", screenshot,
screenshot->resource);
struct screenshot_state *state = calloc(1, sizeof(struct screenshot_state)); struct screenshot_state *state = calloc(1, sizeof(struct screenshot_state));
if (!state) { if (!state) {
wl_client_post_no_memory(client); wl_resource_destroy(screenshot->resource);
free(screenshot);
wl_resource_post_no_memory(screenshooter_resource);
return; return;
} }
state->width = width; state->width = width;
@ -117,13 +126,17 @@ static struct orbital_screenshooter_interface screenshooter_impl = {
.shoot = screenshooter_shoot, .shoot = screenshooter_shoot,
}; };
static void screenshooter_bind(struct wl_client *wl_client, static void screenshooter_bind(struct wl_client *wl_client, void *data,
void *_screenshooter, uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_screenshooter *screenshooter = _screenshooter; struct wlr_screenshooter *screenshooter = data;
assert(wl_client && screenshooter); assert(wl_client && screenshooter);
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&orbital_screenshooter_interface, version, id); &orbital_screenshooter_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &screenshooter_impl, wl_resource_set_implementation(wl_resource, &screenshooter_impl,
screenshooter, NULL); screenshooter, NULL);
} }
@ -137,13 +150,12 @@ struct wlr_screenshooter *wlr_screenshooter_create(struct wl_display *display,
} }
screenshooter->renderer = renderer; screenshooter->renderer = renderer;
struct wl_global *wl_global = wl_global_create(display, screenshooter->wl_global = wl_global_create(display,
&orbital_screenshooter_interface, 1, screenshooter, screenshooter_bind); &orbital_screenshooter_interface, 1, screenshooter, screenshooter_bind);
if (!wl_global) { if (screenshooter->wl_global == NULL) {
free(screenshooter); free(screenshooter);
return NULL; return NULL;
} }
screenshooter->wl_global = wl_global;
return screenshooter; return screenshooter;
} }

View file

@ -65,9 +65,9 @@ static void wl_pointer_destroy(struct wl_resource *resource) {
} }
static void wl_seat_get_pointer(struct wl_client *client, static void wl_seat_get_pointer(struct wl_client *client,
struct wl_resource *pointer_resource, uint32_t id) { struct wl_resource *seat_resource, uint32_t id) {
struct wlr_seat_client *seat_client = struct wlr_seat_client *seat_client =
wl_resource_get_user_data(pointer_resource); wl_resource_get_user_data(seat_resource);
if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) { if (!(seat_client->seat->capabilities & WL_SEAT_CAPABILITY_POINTER)) {
return; return;
} }
@ -78,7 +78,11 @@ static void wl_seat_get_pointer(struct wl_client *client,
wl_resource_destroy(seat_client->pointer); wl_resource_destroy(seat_client->pointer);
} }
seat_client->pointer = wl_resource_create(client, &wl_pointer_interface, seat_client->pointer = wl_resource_create(client, &wl_pointer_interface,
wl_resource_get_version(pointer_resource), id); wl_resource_get_version(seat_resource), id);
if (seat_client->pointer == NULL) {
wl_resource_post_no_memory(seat_resource);
return;
}
wl_resource_set_implementation(seat_client->pointer, &wl_pointer_impl, wl_resource_set_implementation(seat_client->pointer, &wl_pointer_impl,
seat_client, &wl_pointer_destroy); seat_client, &wl_pointer_destroy);
} }
@ -126,6 +130,10 @@ static void wl_seat_get_keyboard(struct wl_client *client,
} }
seat_client->keyboard = wl_resource_create(client, &wl_keyboard_interface, seat_client->keyboard = wl_resource_create(client, &wl_keyboard_interface,
wl_resource_get_version(seat_resource), id); wl_resource_get_version(seat_resource), id);
if (seat_client->keyboard == NULL) {
wl_resource_post_no_memory(seat_resource);
return;
}
wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl, wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl,
seat_client, &wl_keyboard_destroy); seat_client, &wl_keyboard_destroy);
@ -162,6 +170,10 @@ static void wl_seat_get_touch(struct wl_client *client,
} }
seat_client->touch = wl_resource_create(client, &wl_touch_interface, seat_client->touch = wl_resource_create(client, &wl_touch_interface,
wl_resource_get_version(seat_resource), id); wl_resource_get_version(seat_resource), id);
if (seat_client->touch == NULL) {
wl_resource_post_no_memory(seat_resource);
return;
}
wl_resource_set_implementation(seat_client->touch, &wl_touch_impl, wl_resource_set_implementation(seat_client->touch, &wl_touch_impl,
seat_client, &wl_touch_destroy); seat_client, &wl_touch_destroy);
} }
@ -213,6 +225,11 @@ static void wl_seat_bind(struct wl_client *client, void *_wlr_seat,
} }
seat_client->wl_resource = seat_client->wl_resource =
wl_resource_create(client, &wl_seat_interface, version, id); wl_resource_create(client, &wl_seat_interface, version, id);
if (seat_client->wl_resource == NULL) {
free(seat_client);
wl_client_post_no_memory(client);
return;
}
seat_client->client = client; seat_client->client = client;
seat_client->seat = wlr_seat; seat_client->seat = wlr_seat;
wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl, wl_resource_set_implementation(seat_client->wl_resource, &wl_seat_impl,

View file

@ -73,8 +73,8 @@ static void server_decoration_manager_handle_create(struct wl_client *client,
decoration->resource = wl_resource_create(client, decoration->resource = wl_resource_create(client,
&org_kde_kwin_server_decoration_interface, version, id); &org_kde_kwin_server_decoration_interface, version, id);
if (decoration->resource == NULL) { if (decoration->resource == NULL) {
wl_client_post_no_memory(client);
free(decoration); free(decoration);
wl_client_post_no_memory(client);
return; return;
} }
wl_resource_set_implementation(decoration->resource, wl_resource_set_implementation(decoration->resource,
@ -120,9 +120,9 @@ void server_decoration_manager_destroy_resource(struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource)); wl_list_remove(wl_resource_get_link(resource));
} }
static void server_decoration_manager_bind(struct wl_client *client, static void server_decoration_manager_bind(struct wl_client *client, void *data,
void *_manager, uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_server_decoration_manager *manager = _manager; struct wlr_server_decoration_manager *manager = data;
assert(client && manager); assert(client && manager);
struct wl_resource *resource = wl_resource_create(client, struct wl_resource *resource = wl_resource_create(client,

View file

@ -819,14 +819,21 @@ static void subsurface_handle_parent_destroy(struct wl_listener *listener,
void wlr_surface_make_subsurface(struct wlr_surface *surface, void wlr_surface_make_subsurface(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t id) { struct wlr_surface *parent, uint32_t id) {
struct wl_client *client = wl_resource_get_client(surface->resource);
assert(surface->subsurface == NULL); assert(surface->subsurface == NULL);
struct wlr_subsurface *subsurface = struct wlr_subsurface *subsurface =
calloc(1, sizeof(struct wlr_subsurface)); calloc(1, sizeof(struct wlr_subsurface));
if (!subsurface) { if (!subsurface) {
wl_client_post_no_memory(client);
return; return;
} }
subsurface->cached = wlr_surface_state_create(); subsurface->cached = wlr_surface_state_create();
if (subsurface->cached == NULL) {
free(subsurface);
wl_client_post_no_memory(client);
return;
}
subsurface->synchronized = true; subsurface->synchronized = true;
subsurface->surface = surface; subsurface->surface = surface;
@ -840,10 +847,14 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
wl_list_insert(&parent->subsurface_pending_list, wl_list_insert(&parent->subsurface_pending_list,
&subsurface->parent_pending_link); &subsurface->parent_pending_link);
struct wl_client *client = wl_resource_get_client(surface->resource);
subsurface->resource = subsurface->resource =
wl_resource_create(client, &wl_subsurface_interface, 1, id); wl_resource_create(client, &wl_subsurface_interface, 1, id);
if (subsurface->resource == NULL) {
wlr_surface_state_destroy(subsurface->cached);
free(subsurface);
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(subsurface->resource, wl_resource_set_implementation(subsurface->resource,
&subsurface_implementation, subsurface, &subsurface_implementation, subsurface,

View file

@ -506,19 +506,19 @@ static int shell_surface_ping_timeout(void *user_data) {
} }
static void shell_protocol_get_shell_surface(struct wl_client *client, static void shell_protocol_get_shell_surface(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *shell_resource, uint32_t id,
struct wl_resource *surface_resource) { struct wl_resource *surface_resource) {
struct wlr_surface *surface = wl_resource_get_user_data(surface_resource); struct wlr_surface *surface = wl_resource_get_user_data(surface_resource);
if (wlr_surface_set_role(surface, wlr_wl_shell_surface_role, if (wlr_surface_set_role(surface, wlr_wl_shell_surface_role,
resource, WL_SHELL_ERROR_ROLE)) { shell_resource, WL_SHELL_ERROR_ROLE)) {
return; return;
} }
struct wlr_wl_shell *wl_shell = wl_resource_get_user_data(resource); struct wlr_wl_shell *wl_shell = wl_resource_get_user_data(shell_resource);
struct wlr_wl_shell_surface *wl_surface = struct wlr_wl_shell_surface *wl_surface =
calloc(1, sizeof(struct wlr_wl_shell_surface)); calloc(1, sizeof(struct wlr_wl_shell_surface));
if (wl_surface == NULL) { if (wl_surface == NULL) {
wl_client_post_no_memory(client); wl_resource_post_no_memory(shell_resource);
return; return;
} }
wl_list_init(&wl_surface->grab_link); wl_list_init(&wl_surface->grab_link);
@ -530,13 +530,20 @@ static void shell_protocol_get_shell_surface(struct wl_client *client,
wl_surface->surface = surface; wl_surface->surface = surface;
wl_surface->resource = wl_resource_create(client, wl_surface->resource = wl_resource_create(client,
&wl_shell_surface_interface, wl_resource_get_version(resource), id); &wl_shell_surface_interface, wl_resource_get_version(shell_resource),
wlr_log(L_DEBUG, "new wl_shell %p (res %p)", wl_surface, id);
wl_surface->resource); if (wl_surface->resource == NULL) {
free(wl_surface);
wl_resource_post_no_memory(shell_resource);
return;
}
wl_resource_set_implementation(wl_surface->resource, wl_resource_set_implementation(wl_surface->resource,
&shell_surface_impl, wl_surface, &shell_surface_impl, wl_surface,
shell_surface_resource_destroy); shell_surface_resource_destroy);
wlr_log(L_DEBUG, "new wl_shell %p (res %p)", wl_surface,
wl_surface->resource);
wl_signal_init(&wl_surface->events.destroy); wl_signal_init(&wl_surface->events.destroy);
wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.ping_timeout);
wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_move);
@ -574,13 +581,17 @@ static void shell_destroy(struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource)); wl_list_remove(wl_resource_get_link(resource));
} }
static void shell_bind(struct wl_client *wl_client, void *_wl_shell, static void shell_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_wl_shell *wl_shell = _wl_shell; struct wlr_wl_shell *wl_shell = data;
assert(wl_client && wl_shell); assert(wl_client && wl_shell);
struct wl_resource *wl_resource = wl_resource_create(wl_client, struct wl_resource *wl_resource = wl_resource_create(wl_client,
&wl_shell_interface, version, id); &wl_shell_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource, &shell_impl, wl_shell, wl_resource_set_implementation(wl_resource, &shell_impl, wl_shell,
shell_destroy); shell_destroy);
wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource)); wl_list_insert(&wl_shell->wl_resources, wl_resource_get_link(wl_resource));

View file

@ -343,8 +343,8 @@ static void xdg_shell_create_positioner(struct wl_client *wl_client,
wl_resource_get_version(resource), wl_resource_get_version(resource),
id); id);
if (positioner->resource == NULL) { if (positioner->resource == NULL) {
wl_client_post_no_memory(wl_client);
free(positioner); free(positioner);
wl_client_post_no_memory(wl_client);
return; return;
} }
@ -486,7 +486,7 @@ static void xdg_surface_get_popup(struct wl_client *client,
surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6)); surface->popup_state = calloc(1, sizeof(struct wlr_xdg_popup_v6));
if (!surface->popup_state) { if (!surface->popup_state) {
wl_client_post_no_memory(client); wl_resource_post_no_memory(resource);
return; return;
} }
@ -495,6 +495,7 @@ static void xdg_surface_get_popup(struct wl_client *client,
wl_resource_get_version(resource), id); wl_resource_get_version(resource), id);
if (surface->popup_state->resource == NULL) { if (surface->popup_state->resource == NULL) {
free(surface->popup_state); free(surface->popup_state);
wl_resource_post_no_memory(resource);
return; return;
} }
@ -735,7 +736,7 @@ static void xdg_surface_get_toplevel(struct wl_client *client,
surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6)); surface->toplevel_state = calloc(1, sizeof(struct wlr_xdg_toplevel_v6));
if (surface->toplevel_state == NULL) { if (surface->toplevel_state == NULL) {
wl_client_post_no_memory(client); wl_resource_post_no_memory(resource);
return; return;
} }
@ -744,6 +745,11 @@ static void xdg_surface_get_toplevel(struct wl_client *client,
struct wl_resource *toplevel_resource = wl_resource_create(client, struct wl_resource *toplevel_resource = wl_resource_create(client,
&zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id);
if (toplevel_resource == NULL) {
free(surface->toplevel_state);
wl_resource_post_no_memory(resource);
return;
}
surface->toplevel_state->resource = toplevel_resource; surface->toplevel_state->resource = toplevel_resource;
@ -1118,9 +1124,20 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
surface->resource = wl_resource_create(wl_client, surface->resource = wl_resource_create(wl_client,
&zxdg_surface_v6_interface, wl_resource_get_version(client_resource), &zxdg_surface_v6_interface, wl_resource_get_version(client_resource),
id); id);
if (surface->resource == NULL) {
free(surface->next_geometry);
free(surface->geometry);
free(surface);
wl_client_post_no_memory(wl_client);
return;
}
if (wlr_surface_has_buffer(surface->surface)) { if (wlr_surface_has_buffer(surface->surface)) {
wl_resource_post_error(surface->resource, wl_resource_destroy(surface->resource);
free(surface->next_geometry);
free(surface->geometry);
free(surface);
wl_resource_post_error(surface_resource,
ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER, ZXDG_SURFACE_V6_ERROR_UNCONFIGURED_BUFFER,
"xdg_surface must not have a buffer at creation"); "xdg_surface must not have a buffer at creation");
return; return;
@ -1199,9 +1216,9 @@ static int wlr_xdg_client_v6_ping_timeout(void *user_data) {
return 1; return 1;
} }
static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell, static void xdg_shell_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) { uint32_t version, uint32_t id) {
struct wlr_xdg_shell_v6 *xdg_shell = _xdg_shell; struct wlr_xdg_shell_v6 *xdg_shell = data;
assert(wl_client && xdg_shell); assert(wl_client && xdg_shell);
struct wlr_xdg_client_v6 *client = struct wlr_xdg_client_v6 *client =
@ -1215,6 +1232,11 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell,
client->resource = client->resource =
wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id); wl_resource_create(wl_client, &zxdg_shell_v6_interface, version, id);
if (client->resource == NULL) {
free(client);
wl_client_post_no_memory(wl_client);
return;
}
client->client = wl_client; client->client = wl_client;
client->shell = xdg_shell; client->shell = xdg_shell;