From 08b58c7c125a63d6902bbe2eb073dd72f3f006b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 15 Aug 2013 12:26:42 -0700 Subject: [PATCH] compositor: Handle OOM in weston_buffer_from_resource() Handle NULL-return in call-sites as well. --- src/compositor.c | 27 ++++++++++++++++----------- src/screenshooter.c | 4 ++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 8da348ad..c084b923 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -1077,17 +1077,18 @@ weston_buffer_from_resource(struct wl_resource *resource) listener = wl_resource_get_destroy_listener(resource, weston_buffer_destroy_handler); - if (listener) { - buffer = container_of(listener, struct weston_buffer, - destroy_listener); - } else { - buffer = zalloc(sizeof *buffer); - buffer->resource = resource; - wl_signal_init(&buffer->destroy_signal); - buffer->destroy_listener.notify = weston_buffer_destroy_handler; - wl_resource_add_destroy_listener(resource, - &buffer->destroy_listener); - } + if (listener) + return container_of(listener, struct weston_buffer, + destroy_listener); + + buffer = zalloc(sizeof *buffer); + if (buffer == NULL) + return NULL; + + buffer->resource = resource; + wl_signal_init(&buffer->destroy_signal); + buffer->destroy_listener.notify = weston_buffer_destroy_handler; + wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); return buffer; } @@ -1443,6 +1444,10 @@ surface_attach(struct wl_client *client, if (buffer_resource) buffer = weston_buffer_from_resource(buffer_resource); + if (buffer == NULL) { + wl_client_post_no_memory(client); + return; + } /* Attach, attach, without commit in between does not send * wl_buffer.release. */ diff --git a/src/screenshooter.c b/src/screenshooter.c index 24140151..a89194ee 100644 --- a/src/screenshooter.c +++ b/src/screenshooter.c @@ -180,6 +180,10 @@ screenshooter_shoot(struct wl_client *client, struct weston_buffer *buffer = weston_buffer_from_resource(buffer_resource); + if (buffer == NULL) { + wl_resource_post_no_memory(resource); + return; + } if (!wl_shm_buffer_get(buffer->resource)) return;