Skip to contentSkip to conversation

ui/egl: fix render node cleanup order

PATCH In review [email protected] 2 participants 2 messages Aug 20 – Aug 24

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/egl: fix render node cleanup order

From: Marc-André Lureau <[email protected]>

ASAN detected some memory leaks when terminating. Release thread-bound EGL state first, destroy the context and terminate the display while the GBM device is still alive, then destroy GBM and close the render-node fd.

---
 ui/egl-helpers.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
ui/egl-helpers.c +9 -6
index 4ebf364397c1..8e3729a54d15 100644
@@ -736,19 +736,22 @@ bool egl_init(const char *rendernode, DisplayGLMode mode, Error **errp)
 
 void egl_cleanup(void)
 {
+    if (qemu_egl_display) {
+        eglReleaseThread();
+    }
+
     if (qemu_egl_rn_ctx) {
         eglDestroyContext(qemu_egl_display, qemu_egl_rn_ctx);
         qemu_egl_rn_ctx = NULL;
     }
 
+    if (qemu_egl_display) {
+        eglTerminate(qemu_egl_display);
+        qemu_egl_display = NULL;
+    }
+
 #ifdef CONFIG_GBM
     g_clear_pointer(&qemu_egl_rn_gbm_dev, gbm_device_destroy);
     g_clear_fd(&qemu_egl_rn_fd, NULL);
 #endif
-
-    if (qemu_egl_display) {
-        eglReleaseThread();
-        eglTerminate(qemu_egl_display);
-        qemu_egl_display = NULL;
-    }
 }
Signature · 1 line
2.55.0.543.g5ebe2ebe4ea8
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On 2026/08/20 22:20, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

ASAN detected some memory leaks when terminating. Release thread-bound EGL state first, destroy the context and terminate the display while the GBM device is still alive, then destroy GBM and close the render-node fd.

You may also add:

Fixes a3cf9b55bbdc ("ui/egl: implement display and EGL cleanup")

Regards,
Akihiko Odaki