mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
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
This commit is contained in:
parent
4fb652c27f
commit
6666604f17
1 changed files with 9 additions and 6 deletions
15
render/egl.c
15
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue