From 6666604f177739de963271b57a76a62ff64359d1 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Tue, 26 Oct 2021 18:51:30 +0200 Subject: [PATCH] render/egl.c: Fix memory leaks in egl_create calloc is moved to right before egl is called to avoid requiring to free() unused memory. Found via scan-build --- render/egl.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/render/egl.c b/render/egl.c index 712a61c8..a1846c3e 100644 --- a/render/egl.c +++ b/render/egl.c @@ -157,12 +157,6 @@ out: } static struct wlr_egl *egl_create(void) { - struct wlr_egl *egl = calloc(1, sizeof(struct wlr_egl)); - if (egl == NULL) { - wlr_log_errno(WLR_ERROR, "Allocation failed"); - return NULL; - } - const char *client_exts_str = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); if (client_exts_str == NULL) { if (eglGetError() == EGL_BAD_DISPLAY) { @@ -172,12 +166,20 @@ static struct wlr_egl *egl_create(void) { } return NULL; } + wlr_log(WLR_INFO, "Supported EGL client extensions: %s", client_exts_str); if (!check_egl_ext(client_exts_str, "EGL_EXT_platform_base")) { wlr_log(WLR_ERROR, "EGL_EXT_platform_base not supported"); return NULL; } + + struct wlr_egl *egl = calloc(1, sizeof(struct wlr_egl)); + if (egl == NULL) { + wlr_log_errno(WLR_ERROR, "Allocation failed"); + return NULL; + } + load_egl_proc(&egl->procs.eglGetPlatformDisplayEXT, "eglGetPlatformDisplayEXT"); @@ -215,6 +217,7 @@ static struct wlr_egl *egl_create(void) { if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) { wlr_log(WLR_ERROR, "Failed to bind to the OpenGL ES API"); + free(egl); return NULL; }