From: Emil Velikov Date: Fri, 5 Jul 2019 10:14:30 +0000 (+0100) Subject: egl/drm: ensure the backing gbm is set before using it X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=72b97ad9b2bc84742d289219f9129a68040baf0e;hp=4bf7e7b17092487b6b6c4aff5e920dbe1fd4470e egl/drm: ensure the backing gbm is set before using it Currently, if we error out before gbm_dri is set (say due to a different name of the backing GBM implementation, or otherwise) the tear down will trigger a NULL ptr deref and crash out. Move the gbm_dri initialization as early as possible. v2: Drop check in dri2_teardowm_drm (Eric) Reported-by: Christian Gmeiner Cc: Christian Gmeiner Cc: mesa-stable@lists.freedesktop.org Signed-off-by: Emil Velikov Reviewed-by: Eric Engestrom --- diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index 42d79da7b02..b0a2af6bf3d 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -715,6 +715,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) goto cleanup; } } + dri2_dpy->gbm_dri = gbm_dri_device(gbm); if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) { err = "DRI2: gbm device using incorrect/incompatible backend"; @@ -729,7 +730,6 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) disp->Device = dev; - dri2_dpy->gbm_dri = gbm_dri_device(gbm); dri2_dpy->driver_name = strdup(dri2_dpy->gbm_dri->driver_name); dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen;