From b0f33e9736116a1a6a7bd8bade51d473d7373daa Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 11 Jun 2015 13:07:08 +0100 Subject: [PATCH] egl/haiku: plug some obvious memory leaks Cc: Alexander von Gluck IV Acked-by: Brian Paul Signed-off-by: Emil Velikov --- src/egl/drivers/haiku/egl_haiku.cpp | 32 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp index 154b3af7e07..da72895ac04 100644 --- a/src/egl/drivers/haiku/egl_haiku.cpp +++ b/src/egl/drivers/haiku/egl_haiku.cpp @@ -192,18 +192,22 @@ haiku_add_configs_for_visuals(_EGLDisplay *dpy) TRACE("Config configuated\n"); if (!_eglValidateConfig(&conf->base, EGL_FALSE)) { _eglLog(_EGL_DEBUG, "Haiku: failed to validate config"); - return EGL_FALSE; + goto cleanup; } TRACE("Validated config\n"); _eglLinkConfig(&conf->base); if (!_eglGetArraySize(dpy->Configs)) { _eglLog(_EGL_WARNING, "Haiku: failed to create any config"); - return EGL_FALSE; + goto cleanup; } TRACE("Config successfull\n"); - + return EGL_TRUE; + +cleanup: + free(conf); + return EGL_FALSE; } extern "C" @@ -213,7 +217,8 @@ init_haiku(_EGLDriver *drv, _EGLDisplay *dpy) CALLED(); TRACE("Add configs\n"); - haiku_add_configs_for_visuals(dpy); + if (!haiku_add_configs_for_visuals(dpy)) + return EGL_FALSE; dpy->Version = 14; @@ -246,10 +251,14 @@ haiku_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf, } if (!_eglInitContext(&context->ctx, disp, conf, attrib_list)) - ERROR("ERROR creating context"); + goto cleanup; TRACE("Context created\n"); return &context->ctx; + +cleanup: + free(context); + return NULL; } @@ -257,7 +266,13 @@ extern "C" EGLBoolean haiku_destroy_context(_EGLDriver* drv, _EGLDisplay *disp, _EGLContext* ctx) { - ctx=NULL; + struct haiku_egl_context* context = haiku_egl_context(ctx); + + if (_eglPutContext(ctx)) { + // XXX: teardown the context ? + free(context); + ctx = NULL + } return EGL_TRUE; } @@ -273,7 +288,10 @@ haiku_make_current(_EGLDriver* drv, _EGLDisplay* dpy, _EGLSurface *dsurf, struct haiku_egl_surface* surf=haiku_egl_surface(dsurf); _EGLContext *old_ctx; _EGLSurface *old_dsurf, *old_rsurf; - _eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf); + + if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf)) + return EGL_FALSE; + //cont->ctx.DrawSurface=&surf->surf; surf->gl->LockGL(); return EGL_TRUE; -- 2.30.2