Mesa (master): glx: fix possible memory leaks in dri2CreateScreen()

Brian Paul brianp at kemper.freedesktop.org
Fri Jan 29 15:44:58 UTC 2010


Module: Mesa
Branch: master
Commit: 81cca6d4538bdde1661ce868af2a5de47cd251ab
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=81cca6d4538bdde1661ce868af2a5de47cd251ab

Author: Rodolfo Ribeiro Gomes <rodolforg at gmail.com>
Date:   Fri Jan 29 08:36:47 2010 -0700

glx: fix possible memory leaks in dri2CreateScreen()

Original patch fixed up by Brian Paul.

---

 src/glx/x11/dri2_glx.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index 7b0c52b..2228958 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -504,8 +504,10 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
    psc->ext_list_first_time = GL_TRUE;
 
    if (!DRI2Connect(psc->dpy, RootWindow(psc->dpy, screen),
-		    &driverName, &deviceName))
+		    &driverName, &deviceName)) {
+      XFree(psp);
       return NULL;
+   }
 
    psc->driver = driOpenDriver(driverName);
    if (psc->driver == NULL) {
@@ -534,17 +536,17 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
    psc->fd = open(deviceName, O_RDWR);
    if (psc->fd < 0) {
       ErrorMessageF("failed to open drm device: %s\n", strerror(errno));
-      return NULL;
+      goto handle_error;
    }
 
    if (drmGetMagic(psc->fd, &magic)) {
       ErrorMessageF("failed to get magic\n");
-      return NULL;
+      goto handle_error;
    }
 
    if (!DRI2Authenticate(psc->dpy, RootWindow(psc->dpy, screen), magic)) {
       ErrorMessageF("failed to authenticate magic %d\n", magic);
-      return NULL;
+      goto handle_error;
    }
 
    /* If the server does not support the protocol for
@@ -558,7 +560,7 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
 
    if (psc->__driScreen == NULL) {
       ErrorMessageF("failed to create dri screen\n");
-      return NULL;
+      goto handle_error;
    }
 
    driBindCommonExtensions(psc);
@@ -602,6 +604,7 @@ dri2CreateScreen(__GLXscreenConfigs * psc, int screen,
 handle_error:
    Xfree(driverName);
    Xfree(deviceName);
+   XFree(psp);
 
    /* FIXME: clean up here */
 




More information about the mesa-commit mailing list