mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-11-01 22:58:40 -04:00
wayland-server: Remove error event posting from wl_resource_create
The wl_client_add/new_object() functions sends out an NO_MEMORY error if the allocation fails. This was convenient in a couple of places where that was all the error handling that was needed. Unfortunately that looks like out-of-memory isn't handled at the call site and set a bad precedent for not cleaning up properly or not handling at all. As we're introducing wl_resource_create() as a replacement for those two functions, let's remove the automatic error event posting and require the caller to do that if necessary. This commit also introduces a new helper, wl_client_post_no_memory() to make it possible to send NO_MEMORY events from bind where we don't have a wl_resource.
This commit is contained in:
parent
b5b1165008
commit
c82a52a47e
3 changed files with 60 additions and 9 deletions
|
|
@ -115,7 +115,7 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
|
|||
|
||||
buffer = malloc(sizeof *buffer);
|
||||
if (buffer == NULL) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -129,6 +129,13 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
|
|||
|
||||
buffer->resource =
|
||||
wl_resource_create(client, &wl_buffer_interface, 1, id);
|
||||
if (buffer->resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
shm_pool_unref(pool);
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(buffer->resource,
|
||||
&shm_buffer_interface,
|
||||
buffer, destroy_buffer);
|
||||
|
|
@ -182,7 +189,7 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
|||
|
||||
pool = malloc(sizeof *pool);
|
||||
if (pool == NULL) {
|
||||
wl_resource_post_no_memory(resource);
|
||||
wl_client_post_no_memory(client);
|
||||
goto err_close;
|
||||
}
|
||||
|
||||
|
|
@ -207,8 +214,12 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
|||
|
||||
pool->resource =
|
||||
wl_resource_create(client, &wl_shm_pool_interface, 1, id);
|
||||
if (!pool->resource)
|
||||
goto err_free;
|
||||
if (!pool->resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
munmap(pool->data, pool->size);
|
||||
free(pool);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(pool->resource,
|
||||
&shm_pool_interface,
|
||||
|
|
@ -233,6 +244,11 @@ bind_shm(struct wl_client *client,
|
|||
struct wl_resource *resource;
|
||||
|
||||
resource = wl_resource_create(client, &wl_shm_interface, 1, id);
|
||||
if (!resource) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(resource, &shm_interface, data, NULL);
|
||||
|
||||
wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888);
|
||||
|
|
@ -276,6 +292,11 @@ wl_shm_buffer_create(struct wl_client *client,
|
|||
|
||||
buffer->resource =
|
||||
wl_resource_create(client, &wl_buffer_interface, 1, id);
|
||||
if (buffer->resource == NULL) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(buffer->resource,
|
||||
&shm_buffer_interface,
|
||||
buffer, destroy_buffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue