backend: egl: fix resource leak

Destroy context and surface as well in egl_deinit.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2022-09-29 19:09:59 +01:00
parent 0fe4e0a1d4
commit c1dc11f59c
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
1 changed files with 13 additions and 3 deletions

View File

@ -66,10 +66,20 @@ void egl_deinit(backend_t *base) {
gl_deinit(&gd->gl);
// Destroy GLX context
if (gd->ctx) {
if (gd->ctx != EGL_NO_CONTEXT) {
eglMakeCurrent(gd->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(gd->display, gd->ctx);
gd->ctx = 0;
gd->ctx = EGL_NO_CONTEXT;
}
if (gd->target_win != EGL_NO_SURFACE) {
eglDestroySurface(gd->display, gd->target_win);
gd->target_win = EGL_NO_SURFACE;
}
if (gd->display != EGL_NO_DISPLAY) {
eglTerminate(gd->display);
gd->display = EGL_NO_DISPLAY;
}
free(gd);
@ -173,7 +183,7 @@ static backend_t *egl_init(session_t *ps) {
}
gd->ctx = eglCreateContext(gd->display, target_cfg, NULL, NULL);
if (!gd->ctx) {
if (gd->ctx == EGL_NO_CONTEXT) {
log_error("Failed to get GLX context.");
goto end;
}