[PATCH weston] compositor: create_data_source(): Fix potential crash on OOM

Bryce Harrington bryce at osg.samsung.com
Wed Jan 13 14:46:23 PST 2016


On Mon, Jan 11, 2016 at 09:23:01AM +0100, Marek Chalupa wrote:
> Hi,
> 
> Reviewed-by: Marek Chalupa <mchqwerty at gmail.com>
> 
> (one small comment below)
> 
> Cheers,
> Marek
> 
> On 01/05/2016 05:18 PM, Lyude wrote:
> >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 at redhat.com>
> >---
> >  src/data-device.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> >diff --git a/src/data-device.c b/src/data-device.c
> >index d3ead5f..966d3b4 100644
> >--- a/src/data-device.c
> >+++ b/src/data-device.c
> >@@ -881,6 +881,14 @@ create_data_source(struct wl_client *client,
> >  		return;
> >  	}
> >
> >+	source->resource =
> >+		wl_resource_create(client, &wl_data_source_interface, 1, id);
> >+	if (source->resource == NULL) {
> >+		wl_resource_post_no_memory(resource);
> >+		free(source);
> 
> Maybe it would be better to free the source before posting no-memory
> event, since wl_resource_post_no_memory() will try to allocate new
> memory for the event (and we're already OOM)

Good point, I've made this hotfix and pushed the patch, thanks.

Reviewed-by: Bryce Harrington <bryce at osg.samsung.com>

Pushed:
To ssh://git.freedesktop.org/git/wayland/weston
   553d124..c9f8f8a  master -> master
 
> >+		return;
> >+	}
> >+
> >  	wl_signal_init(&source->destroy_signal);
> >  	source->accept = client_source_accept;
> >  	source->send = client_source_send;
> >@@ -888,8 +896,6 @@ create_data_source(struct wl_client *client,
> >
> >  	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,
> >  				       source, destroy_data_source);
> >  }
> >
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list