egl/dri2: Add reference count for dri2_egl_display

Graphics / Mesa 3D Graphics Library / Mesa - Nicolas Boichat [chromium.org] - 28 July 2016 08:08 UTC

android.opengl.cts.WrapperTest#testGetIntegerv1 CTS test calls eglTerminate, followed by eglReleaseThread. A similar case is observed in this bug: https://bugs.freedesktop.org/show_bug.cgi?id=69622, where the test calls eglTerminate, then eglMakeCurrent(dpy, NULL, NULL, NULL).

With the current code, dri2_dpy structure is freed on eglTerminate call, so the display is not initialized when eglReleaseThread calls MakeCurrent with NULL parameters, to unbind the context, which causes a a segfault in drv->API.MakeCurrent (dri2_make_current), either in glFlush or in a latter call.

eglTerminate specifies that "If contexts or surfaces associated with display is current to any thread, they are not released until they are no longer current as a result of eglMakeCurrent."

However, to properly free the current context/surface (i.e., call glFlush, unbindContext, driDestroyContext), we still need the display vtbl (and possibly an active dri dpy connection). Therefore, we add some reference counter to dri2_egl_display, to make sure the structure is kept allocated as long as it is required.

One drawback of this is that eglInitialize may not completely reinitialize the display (if eglTerminate was called with a current context), however, this seems to meet the EGL spec quite well, and does not permanently leak any context/display even for incorrectly written apps.

Cc: "12.0"

9ee683f egl/dri2: Add reference count for dri2_egl_display
src/egl/drivers/dri2/egl_dri2.c | 111 ++++++++++++++++++++++++++++++++-------
src/egl/drivers/dri2/egl_dri2.h | 4 ++
2 files changed, 95 insertions(+), 20 deletions(-)

Upstream: cgit.freedesktop.org


  • Share