[PATCH] DRI2: Fix memory leak when a screen is not DRI2 capable.

Kusanagi Kouichi slash at ac.auone-net.jp
Sun Sep 19 05:55:02 PDT 2010


Signed-off-by: Kusanagi Kouichi <slash at ac.auone-net.jp>
---
 glx/glxdri2.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index c2305ad..6dc25ee 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -701,6 +701,7 @@ initializeExtensions(__GLXDRIscreen *screen)
 static __GLXscreen *
 __glXDRIscreenProbe(ScreenPtr pScreen)
 {
+    int fd;
     const char *driverName, *deviceName;
     __GLXDRIscreen *screen;
     char filename[128];
@@ -710,23 +711,23 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     const __DRIconfig **driConfigs;
     int i;
 
-    screen = calloc(1, sizeof *screen);
-    if (screen == NULL)
-	return NULL;
-
     if (!xf86LoaderCheckSymbol("DRI2Connect") ||
-	!DRI2Connect(pScreen, DRI2DriverDRI,
-		     &screen->fd, &driverName, &deviceName)) {
+	!DRI2Connect(pScreen, DRI2DriverDRI, &fd, &driverName, &deviceName)) {
 	LogMessage(X_INFO,
 		   "AIGLX: Screen %d is not DRI2 capable\n", pScreen->myNum);
 	return NULL;
     }
 
+    screen = calloc(1, sizeof *screen);
+    if (screen == NULL)
+	return NULL;
+
     screen->base.destroy        = __glXDRIscreenDestroy;
     screen->base.createContext  = __glXDRIscreenCreateContext;
     screen->base.createDrawable = __glXDRIscreenCreateDrawable;
     screen->base.swapInterval   = __glXDRIdrawableSwapInterval;
     screen->base.pScreen       = pScreen;
+    screen->fd = fd;
 
     __glXInitExtensionEnableBits(screen->glx_enable_bits);
 
-- 
1.7.1



More information about the xorg-devel mailing list