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

Kusanagi Kouichi slash at ac.auone-net.jp
Wed Dec 14 03:43:11 PST 2011


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

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index 8187a3e..b2174f5 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -693,28 +693,29 @@ initializeExtensions(__GLXDRIscreen *screen)
 static __GLXscreen *
 __glXDRIscreenProbe(ScreenPtr pScreen)
 {
+    int fd;
     const char *driverName, *deviceName;
     __GLXDRIscreen *screen;
     size_t buffer_size;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
-    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.7.3



More information about the xorg-devel mailing list