From 0e8e8ba29a7cbe2fe45939cb972f437ccd21bcd5 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sat, 29 Jan 2011 15:00:49 -0800 Subject: [PATCH] glx: Fix leaks in DRI screen creation error paths. Signed-off-by: Brian Paul --- src/glx/dri_glx.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c index 42b263c6377..ff027dc9e9c 100644 --- a/src/glx/dri_glx.c +++ b/src/glx/dri_glx.c @@ -836,26 +836,24 @@ driCreateScreen(int screen, struct glx_display *priv) return NULL; memset(psc, 0, sizeof *psc); - if (!glx_screen_init(&psc->base, screen, priv)) - return NULL; - - if (!driGetDriverName(priv->dpy, screen, &driverName)) { + if (!glx_screen_init(&psc->base, screen, priv)) { Xfree(psc); return NULL; } + if (!driGetDriverName(priv->dpy, screen, &driverName)) { + goto cleanup; + } + psc->driver = driOpenDriver(driverName); Xfree(driverName); - if (psc->driver == NULL) { - Xfree(psc); - return NULL; - } + if (psc->driver == NULL) + goto cleanup; extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS); if (extensions == NULL) { ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - Xfree(psc); - return NULL; + goto cleanup; } for (i = 0; extensions[i]; i++) { @@ -865,19 +863,14 @@ driCreateScreen(int screen, struct glx_display *priv) psc->legacy = (__DRIlegacyExtension *) extensions[i]; } - if (psc->core == NULL || psc->legacy == NULL) { - Xfree(psc); - return NULL; - } + if (psc->core == NULL || psc->legacy == NULL) + goto cleanup; pdp = (struct dri_display *) priv->driDisplay; psc->driScreen = CallCreateNewScreen(psc->base.dpy, screen, psc, pdp); - if (psc->driScreen == NULL) { - dlclose(psc->driver); - Xfree(psc); - return NULL; - } + if (psc->driScreen == NULL) + goto cleanup; extensions = psc->core->getExtensions(psc->driScreen); driBindExtensions(psc, extensions); @@ -902,6 +895,14 @@ driCreateScreen(int screen, struct glx_display *priv) psp->getSwapInterval = driGetSwapInterval; return &psc->base; + +cleanup: + if (psc->driver) + dlclose(psc->driver); + glx_screen_cleanup(&psc->base); + Xfree(psc); + + return NULL; } /* Called from __glXFreeDisplayPrivate. -- 2.30.2