From 4c3f8d3af8a48addd642e1a88701d1be3d8dcaf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Thu, 3 Mar 2022 08:20:46 +0100 Subject: [PATCH] egl/wayland: fix crash in dri2_initialize_wayland_swrast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When "dri2_wl_formats_init" fails in "dri2_initialize_wayland_swrast", the "dri2_display_destroy" function is called for clean up. However, the "dri2_egl_display" was not associated with the display in its "DriverData" field yet. The following cast in "dri2_display_destroy": struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); Expands to: _EGL_DRIVER_TYPECAST(drvname ## _display, _EGLDisplay, obj->DriverData) Crashing. Signed-off-by: José Expósito Part-of: --- src/egl/drivers/dri2/platform_wayland.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index 242cf5891d9..42bdb3b4b15 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -2605,11 +2605,12 @@ dri2_initialize_wayland_swrast(_EGLDisplay *disp) if (!dri2_dpy) return _eglError(EGL_BAD_ALLOC, "eglInitialize"); + dri2_dpy->fd = -1; + disp->DriverData = (void *) dri2_dpy; + if (dri2_wl_formats_init(&dri2_dpy->formats) < 0) goto cleanup; - dri2_dpy->fd = -1; - disp->DriverData = (void *) dri2_dpy; if (disp->PlatformDisplay == NULL) { dri2_dpy->wl_dpy = wl_display_connect(NULL); if (dri2_dpy->wl_dpy == NULL)