Skip to content

egl: set TSD as NULL after deinit

maniraj87 requested to merge eglreleasethread-crash into main

When eglReleaseThread() is called from application's destructor (API with attribute((destructor))), it crashes due to invalid memory access.

In this case, _egl_TLS is freed in the flow of _eglAtExit() as below but _egl_TLS is not set to NULL.

_eglDestroyThreadInfo
    |__ _eglFiniTSD
        |__ _eglAtExit
            |__ __run_exit_handlers
                |__ exit

Later when the eglReleaseThread is called from application's destructor, it ends-up accessing the freed _egl_TLS pointer.

eglReleaseThread -> in libEGL_mesa
    |__ eglReleaseThread -> in libEGL(glvnd)
        |__ destructor() -> App's destructor

To resolve the invalid access, setting the _egl_TLS pointer as NULL after freeing it.

Merge request reports