[PATCH xserver v2] wayland: clear resource for pixmap on unrealize

Olivier Fourdan ofourdan at redhat.com
Mon Jun 6 07:22:28 UTC 2016


On cursor unrealize, the associated pixmap is destroyed, make sure we
clear the pointer from the private resource and check for the value
being non-null when setting or destroying the cursor.

Signed-off-by: Olivier Fourdan <ofourdan at redhat.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96246
---
 v2: Clear the x_cursor from the unrealize callback as well as suggested
     by Rui - Note that when called from DIX's FreeCursor(), the device 
     is always NULL, so we must take some care not to add more NULL
     pointer dereference by doing so...

 hw/xwayland/xwayland-cursor.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c
index 76729db..74dfe4e 100644
--- a/hw/xwayland/xwayland-cursor.c
+++ b/hw/xwayland/xwayland-cursor.c
@@ -76,8 +76,20 @@ static Bool
 xwl_unrealize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor)
 {
     PixmapPtr pixmap;
+    struct xwl_seat *xwl_seat;
 
     pixmap = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
+    if (!pixmap)
+        return TRUE;
+
+    dixSetPrivate(&cursor->devPrivates, &xwl_cursor_private_key, NULL);
+
+    /* When called from FreeCursor(), device is always NULL */
+    if (device) {
+        xwl_seat = device->public.devicePrivate;
+        if (xwl_seat && cursor == xwl_seat->x_cursor)
+            xwl_seat->x_cursor = NULL;
+    }
 
     return xwl_shm_destroy_pixmap(pixmap);
 }
@@ -122,6 +134,9 @@ xwl_seat_set_cursor(struct xwl_seat *xwl_seat)
 
     cursor = xwl_seat->x_cursor;
     pixmap = dixGetPrivate(&cursor->devPrivates, &xwl_cursor_private_key);
+    if (!pixmap)
+        return;
+
     stride = cursor->bits->width * 4;
     if (cursor->bits->argb)
         memcpy(pixmap->devPrivate.ptr,
-- 
2.7.4



More information about the xorg-devel mailing list