aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2021-10-26 18:51:30 +0200
committerSimon Zeni <simon@bl4ckb0ne.ca>2021-10-27 07:30:36 -0600
commit6666604f177739de963271b57a76a62ff64359d1 (patch)
tree31ce10883a61d15439871dc3a2f19744b0516985 /render
parent4fb652c27f68d9b8c3b125f51efe17dbd66a1084 (diff)
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
Diffstat (limited to 'render')
-rw-r--r--render/egl.c15
1 files 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;
}