Skip to content

Fix use-after-free during EGL shutdown #2510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Flamefire
Copy link

atexit is used to eglTerminate the EGL_DISPLAY Any context created using that will fail in glDestroyContext because a stale display is used, i.e. one that was already terminated.

Avoid this by setting EGL_DISPLAY back to None after termination and checking for that before using.

This can be reproduced with MUJOCO_GL=egl python -c 'import mujoco; c = mujoco.GLContext(1280, 960)'

This throws:

Traceback (most recent call last):
  File "/data/cat/ws/s3248973-gputest/venv/lib/python3.11/site-packages/mujoco/egl/__init__.py", line 148, in __del__
  File "/data/cat/ws/s3248973-gputest/venv/lib/python3.11/site-packages/mujoco/egl/__init__.py", line 143, in free
  File "/data/cat/ws/s3248973-gputest/venv/lib/python3.11/site-packages/OpenGL/platform/baseplatform.py", line 488, in __call__
  File "/data/cat/ws/s3248973-gputest/venv/lib/python3.11/site-packages/OpenGL/error.py", line 231, in glCheckError
OpenGL.raw.EGL._errors.EGLError: <exception str() failed>

`atexit` is used to `eglTerminate` the `EGL_DISPLAY`
Any context created using that will fail in `glDestroyContext` because a stale display is used, i.e. one that was already terminated.

Avoid this by setting `EGL_DISPLAY` back to `None` after termination and checking for that before using.
@yuvaltassa yuvaltassa requested a review from saran-t March 18, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant