[PATCH wayland] server: don't send an error to NULL display_resource

Marek Chalupa mchqwerty at gmail.com
Mon Dec 7 00:42:25 PST 2015


if display_resource = wl_resource_create() fails in bind_display(),
we call wl_client_post_no_memory() which is wrong, since this function
uses display_resource (which is NULL at this point). So remove call to
this function (said simply: don't send an error to resource that
you've just failed to create).

Also add a check to wl_client_post_no_memory() for display_resource.
display_resource is destroyed first and only upon client's destruction,
so it is a good marker that the client is being destroyed. Adding a
check for display_resource here makes sure that we won't crash if some
resource destructor or destroy signal handler calls wl_client_post_no_memory()
while destroying client.

https://bugs.freedesktop.org/show_bug.cgi?id=91356

Reported-by: Ashim <ashim.shah at samsung.com>
Signed-off-by: Marek Chalupa <mchqwerty at gmail.com>
---
 src/wayland-server.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/wayland-server.c b/src/wayland-server.c
index 1364d5d..b372aa9 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -511,6 +511,14 @@ wl_client_get_object(struct wl_client *client, uint32_t id)
 WL_EXPORT void
 wl_client_post_no_memory(struct wl_client *client)
 {
+	/* display_resource is destroyed first upon client's destruction
+	 * If some resource destructor calls wl_client_post_no_memory()
+	 * (why it would do it? you never know...), we would pass NULL
+	 * here as a resource to the wl_resource_post_error
+	 * and we don't want that */
+	if (!client->display_resource)
+		return;
+
 	wl_resource_post_error(client->display_resource,
 			       WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
 }
@@ -779,7 +787,8 @@ bind_display(struct wl_client *client, struct wl_display *display)
 	client->display_resource =
 		wl_resource_create(client, &wl_display_interface, 1, 1);
 	if (client->display_resource == NULL) {
-		wl_client_post_no_memory(client);
+		/* Don't send error to client -
+		 * what resource we would use anyway? */
 		return -1;
 	}
 
-- 
2.5.0



More information about the wayland-devel mailing list