[vlc-commits] [Git][videolan/vlc][master] egl_display_gbm: fix error path and leak in Open()

Alexandre Janniaux (@alexandre-janniaux) gitlab at videolan.org
Mon Nov 9 09:15:51 UTC 2026



Alexandre Janniaux pushed to branch master at VideoLAN / VLC


Commits:
df5b2495 by Alexandre Janniaux at 2026-11-09T09:01:18+00:00
egl_display_gbm: fix error path and leak in Open()

When an error happened in the middle of Open(), the sys pointer was
leaked. Refactor the error path so that it's always handled and make
sure to return an appropriate error code, even though they are not
properly propagated for now.

- - - - -


1 changed file:

- modules/video_output/opengl/egl_display_gbm.c


Changes:

=====================================
modules/video_output/opengl/egl_display_gbm.c
=====================================
@@ -98,46 +98,50 @@ static vlc_egl_display_open_fn Open;
 static int
 Open(struct vlc_egl_display *display)
 {
-    struct sys *sys = display->sys = malloc(sizeof(*sys));
-    if (!sys)
-        return VLC_EGENERIC;
-
     const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
     if (!extensions)
         return VLC_EGENERIC;
 
     if (!vlc_gl_StrHasToken(extensions, "EGL_KHR_platform_gbm"))
-        return VLC_EGENERIC;
+        return VLC_ENOTSUP;
+
+    struct sys *sys = malloc(sizeof(*sys));
+    if (!sys)
+        return VLC_ENOMEM;
 
     const char *device_path;
     sys->fd = OpenDeviceFd(&device_path);
     if (sys->fd < 0)
-        return VLC_EGENERIC;
+        goto error;
 
     sys->device = gbm_create_device(sys->fd);
     if (!sys->device)
-    {
-        vlc_close(sys->fd);
-        return VLC_EGENERIC;
-    }
+        goto gbm_error;
 
     display->display = eglGetPlatformDisplay(EGL_PLATFORM_GBM_KHR, sys->device,
                                              NULL);
     if (display->display == EGL_NO_DISPLAY)
-    {
-        gbm_device_destroy(sys->device);
-        vlc_close(sys->fd);
-        return VLC_EGENERIC;
-    }
+        goto egl_error;
 
     static const struct vlc_egl_display_ops ops = {
         .close = Close,
     };
     display->ops = &ops;
+    display->sys = sys;
 
     msg_Info(display, "EGL using GBM platform on device %s (fd=%d)",
                       device_path, sys->fd);
     return VLC_SUCCESS;
+
+egl_error:
+    gbm_device_destroy(sys->device);
+
+gbm_error:
+    vlc_close(sys->fd);
+
+error:
+    free(sys);
+    return VLC_EGENERIC;
 }
 
 vlc_module_begin()



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/df5b24959dcfbf2ee24e97f84079fbbef4d672bd

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/df5b24959dcfbf2ee24e97f84079fbbef4d672bd
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list