xserver: Branch 'master' - 7 commits

Keith Packard keithp at kemper.freedesktop.org
Thu Nov 24 21:08:04 PST 2011


 glx/glxdri.c                   |   15 ++++++++++++---
 glx/glxdri2.c                  |   14 +++++++++++---
 glx/glxdriswrast.c             |   14 +++++++++++---
 glx/glxscreens.c               |   10 ++++++++++
 hw/xfree86/common/xf86Config.c |    6 +++++-
 hw/xfree86/parser/InputClass.c |   15 +++++++++++++++
 hw/xfree86/parser/scan.c       |   28 +++++++++++-----------------
 hw/xfree86/parser/xf86Parser.h |    8 ++++----
 hw/xwin/winconfig.c            |    4 +++-
 9 files changed, 82 insertions(+), 32 deletions(-)

New commits:
commit 873a1ace3646994adf95961f48719e95dcade7a2
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Tue Nov 1 10:57:56 2011 -0200

    parser: free val.str after xstrtokenize
    
    After we tokenize val.str, we discard it.
    
    This is just one example:
    6 bytes in 1 blocks are definitely lost in loss record 24 of 652
       at 0x4C2779D: malloc (in vgpreload_memcheck-amd64-linux.so)
       by 0x4D744D: xf86getToken (scan.c:400)
       by 0x4D75F1: xf86getSubToken (scan.c:462)
       by 0x4DB060: xf86parseInputClassSection (InputClass.c:145)
       by 0x4D664C: xf86readConfigFile (read.c:184)
       by 0x490556: xf86HandleConfigFile (xf86Config.c:2360)
       by 0x49AA77: InitOutput (xf86Init.c:365)
       by 0x425A7A: main (main.c:204)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index 1128995..2cdc912 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -128,54 +128,63 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchProduct");
             add_group_entry(&ptr->match_product,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_VENDOR:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchVendor");
             add_group_entry(&ptr->match_vendor,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_DEVICE_PATH:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchDevicePath");
             add_group_entry(&ptr->match_device,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_OS:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchOS");
             add_group_entry(&ptr->match_os,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_PNPID:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchPnPID");
             add_group_entry(&ptr->match_pnpid,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_USBID:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchUSBID");
             add_group_entry(&ptr->match_usbid,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_DRIVER:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchDriver");
             add_group_entry(&ptr->match_driver,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_TAG:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchTag");
             add_group_entry(&ptr->match_tag,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_LAYOUT:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
                 Error(QUOTE_MSG, "MatchLayout");
             add_group_entry(&ptr->match_layout,
                             xstrtokenize(val.str, TOKEN_SEP));
+            free(val.str);
             break;
         case MATCH_IS_KEYBOARD:
             if (xf86getSubToken(&(ptr->comment)) != STRING)
commit d41987d77c903e00cca7bcf3e04ed07151e3bb4d
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Tue Nov 1 10:42:36 2011 -0200

    parser: free val.str after xf86getBoolValue
    
    After we convert the value to a boolean, we discard the string.
    
    This is just one example:
    
    3 bytes in 1 blocks are definitely lost in loss record 5 of 657
       at 0x4C2779D: malloc (vgpreload_memcheck-amd64-linux.so)
       by 0x4D744D: xf86getToken (scan.c:400)
       by 0x4D75F1: xf86getSubToken (scan.c:462)
       by 0x4DB3E0: xf86parseInputClassSection (InputClass.c:189)
       by 0x4D664C: xf86readConfigFile (read.c:184)
       by 0x490556: xf86HandleConfigFile (xf86Config.c:2360)
       by 0x49AA77: InitOutput (xf86Init.c:365)
       by 0x425A7A: main (main.c:204)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c
index 3f80170..1128995 100644
--- a/hw/xfree86/parser/InputClass.c
+++ b/hw/xfree86/parser/InputClass.c
@@ -182,6 +182,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsKeyboard");
             ptr->is_keyboard.set = xf86getBoolValue(&ptr->is_keyboard.val,
                                                     val.str);
+            free(val.str);
             if (!ptr->is_keyboard.set)
                 Error(BOOL_MSG, "MatchIsKeyboard");
             break;
@@ -190,6 +191,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsPointer");
             ptr->is_pointer.set = xf86getBoolValue(&ptr->is_pointer.val,
                                                    val.str);
+            free(val.str);
             if (!ptr->is_pointer.set)
                 Error(BOOL_MSG, "MatchIsPointer");
             break;
@@ -198,6 +200,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsJoystick");
             ptr->is_joystick.set = xf86getBoolValue(&ptr->is_joystick.val,
                                                     val.str);
+            free(val.str);
             if (!ptr->is_joystick.set)
                 Error(BOOL_MSG, "MatchIsJoystick");
             break;
@@ -206,6 +209,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsTablet");
             ptr->is_tablet.set = xf86getBoolValue(&ptr->is_tablet.val,
                                                   val.str);
+            free(val.str);
             if (!ptr->is_tablet.set)
                 Error(BOOL_MSG, "MatchIsTablet");
             break;
@@ -214,6 +218,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsTouchpad");
             ptr->is_touchpad.set = xf86getBoolValue(&ptr->is_touchpad.val,
                                                     val.str);
+            free(val.str);
             if (!ptr->is_touchpad.set)
                 Error(BOOL_MSG, "MatchIsTouchpad");
             break;
@@ -222,6 +227,7 @@ xf86parseInputClassSection(void)
                 Error(QUOTE_MSG, "MatchIsTouchscreen");
             ptr->is_touchscreen.set = xf86getBoolValue(&ptr->is_touchscreen.val,
                                                        val.str);
+            free(val.str);
             if (!ptr->is_touchscreen.set)
                 Error(BOOL_MSG, "MatchIsTouchscreen");
             break;
commit d5c7338b3eaea55177ade6fcba71a47ccd5547f5
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Mon Oct 31 17:54:03 2011 -0200

    parser: free scandir's list
    
    v2: move the free()s to the function that calls scandir
    
    80 bytes in 1 blocks are definitely lost in loss record 411 of 631
       at 0x4C2779D: malloc (vgpreload_memcheck-amd64-linux.so)
       by 0x4C27927: realloc (vgpreload_memcheck-amd64-linux.so)
       by 0x696A80D: scandir (scandir.c:108)
       by 0x4D8828: OpenConfigDir (scan.c:854)
       by 0x4D8A43: xf86openConfigDirFiles (scan.c:952)
       by 0x49031F: xf86HandleConfigFile (xf86Config.c:2327)
       by 0x49A9E3: InitOutput (xf86Init.c:365)
       by 0x425A7A: main (main.c:204)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index d22d6ab..9099227 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -800,14 +800,12 @@ AddConfigDirFiles(const char *dirpath, struct dirent **list, int num)
 				       "files opened\n");
 				warnOnce = TRUE;
 			}
-			free(list[i]);
 			continue;
 		}
 
 		path = malloc(PATH_MAX + 1);
 		snprintf(path, PATH_MAX + 1, "%s/%s", dirpath,
 			 list[i]->d_name);
-		free(list[i]);
 		file = fopen(path, "r");
 		if (!file) {
 			free(path);
@@ -858,8 +856,10 @@ OpenConfigDir(const char *path, const char *cmdline, const char *projroot,
 		if (!found) {
 			free(dirpath);
 			dirpath = NULL;
-			free(list);
 		}
+		while (num--)
+			free(list[num]);
+		free(list);
 	}
 
 	free(pathcopy);
commit 3d635fe84d6de53e2f74203b10e89f7851fe3fc1
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Sun Oct 30 18:04:59 2011 -0200

    Correctly free config file names
    
    We call xf86penConfigDirFiles twice, so we overwrite the configDirPath
    variable, losing the pointer. If we move the pointer management to the
    upper layer (the function callers), they will be able to call these
    functions as many times as they want, but they'll have to free those
    returned values.
    
    v2: don't leak inside XWin
    
    4,097 bytes in 1 blocks are definitely lost in loss record 625 of 632
       at 0x4C2779D: malloc (in vgpreload_memcheck-amd64-linux.so)
       by 0x4D7899: DoSubstitution (scan.c:615)
       by 0x4D87B0: OpenConfigDir (scan.c:845)
       by 0x4D8A2D: xf86openConfigDirFiles (scan.c:955)
       by 0x49031F: xf86HandleConfigFile (xf86Config.c:2327)
       by 0x49A9BF: InitOutput (xf86Init.c:365)
       by 0x425A7A: main (main.c:204)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 228021b..fef4bf1 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -2300,7 +2300,7 @@ checkInput(serverLayoutPtr layout, Bool implicit_layout) {
 ConfigStatus
 xf86HandleConfigFile(Bool autoconfig)
 {
-    const char *filename, *dirname, *sysdirname;
+    char *filename, *dirname, *sysdirname;
     const char *filesearch, *dirsearch;
     MessageType filefrom = X_DEFAULT;
     MessageType dirfrom = X_DEFAULT;
@@ -2352,6 +2352,10 @@ xf86HandleConfigFile(Bool autoconfig)
 	    return CONFIG_NOFILE;
     }
 
+    free(filename);
+    free(dirname);
+    free(sysdirname);
+
     if ((xf86configptr = xf86readConfigFile ()) == NULL) {
 	xf86Msg(X_ERROR, "Problem parsing the config file\n");
 	return CONFIG_PARSE_ERROR;
diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index e25b1ad..d22d6ab 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -101,8 +101,6 @@ static int builtinIndex = 0;
 static int configPos = 0;		/* current readers position */
 static int configLineNo = 0;	/* linenumber */
 static char *configBuf, *configRBuf;	/* buffer for lines */
-static char *configPath;		/* path to config file */
-static char *configDirPath;		/* path to config dir */
 static char *configSection = NULL;	/* name of current section being parsed */
 static int numFiles = 0;		/* number of config files */
 static int curFileIndex = 0;		/* index of current config file */
@@ -894,7 +892,8 @@ xf86initConfigFiles(void)
  * of the located files.
  *
  * The return value is a pointer to the actual name of the file that was
- * opened.  When no file is found, the return value is NULL.
+ * opened.  When no file is found, the return value is NULL. The caller should
+ * free() the returned value.
  *
  * The escape sequences allowed in the search path are defined above.
  *
@@ -916,7 +915,7 @@ xf86initConfigFiles(void)
 							"%P/lib/X11/%X"
 #endif
 
-const char *
+char *
 xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
 {
 	if (!path || !path[0])
@@ -925,8 +924,7 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
 		projroot = PROJECTROOT;
 
 	/* Search for a config file */
-	configPath = OpenConfigFile(path, cmdline, projroot, XCONFIGFILE);
-	return configPath;
+	return OpenConfigFile(path, cmdline, projroot, XCONFIGFILE);
 }
 
 /*
@@ -939,12 +937,13 @@ xf86openConfigFile(const char *path, const char *cmdline, const char *projroot)
  * fails if it is not found.
  *
  * The return value is a pointer to the actual name of the direcoty that was
- * opened.  When no directory is found, the return value is NULL.
+ * opened.  When no directory is found, the return value is NULL. The caller
+ * should free() the returned value.
  *
  * The escape sequences allowed in the search path are defined above.
  *
  */
-const char *
+char *
 xf86openConfigDirFiles(const char *path, const char *cmdline,
 		       const char *projroot)
 {
@@ -954,8 +953,7 @@ xf86openConfigDirFiles(const char *path, const char *cmdline,
 		projroot = PROJECTROOT;
 
 	/* Search for the multiconf directory */
-	configDirPath = OpenConfigDir(path, cmdline, projroot, XCONFIGDIR);
-	return configDirPath;
+	return OpenConfigDir(path, cmdline, projroot, XCONFIGDIR);
 }
 
 void
@@ -963,10 +961,6 @@ xf86closeConfigFile (void)
 {
 	int i;
 
-	free (configPath);
-	configPath = NULL;
-	free (configDirPath);
-	configDirPath = NULL;
 	free (configRBuf);
 	configRBuf = NULL;
 	free (configBuf);
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index c12bd56..7d4662b 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -487,10 +487,10 @@ xf86ConfigSymTabRec, *xf86ConfigSymTabPtr;
  * prototypes for public functions
  */
 extern void xf86initConfigFiles(void);
-extern const char *xf86openConfigFile(const char *path, const char *cmdline,
-				      const char *projroot);
-extern const char *xf86openConfigDirFiles(const char *path, const char *cmdline,
-					  const char *projroot);
+extern char *xf86openConfigFile(const char *path, const char *cmdline,
+				const char *projroot);
+extern char *xf86openConfigDirFiles(const char *path, const char *cmdline,
+				    const char *projroot);
 extern void xf86setBuiltinConfig(const char *config[]);
 extern XF86ConfigPtr xf86readConfigFile(void);
 extern void xf86closeConfigFile(void);
diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c
index 76bf8e2..4dbbe7c 100644
--- a/hw/xwin/winconfig.c
+++ b/hw/xwin/winconfig.c
@@ -117,7 +117,7 @@ Bool
 winReadConfigfile ()
 {
   Bool		retval = TRUE;
-  const char	*filename, *dirname;
+  char		*filename, *dirname;
   MessageType	filefrom = X_DEFAULT;
   MessageType	dirfrom = X_DEFAULT;
   char		*xf86ConfigFile = NULL;
@@ -169,6 +169,8 @@ winReadConfigfile ()
     {
       return FALSE;
     }
+  free(filename);
+  free(dirname);
   if ((g_xf86configptr = xf86readConfigFile ()) == NULL)
     {
       winMsg (X_ERROR, "Problem parsing the config file\n");
commit 0ae087e13192d9b498db782be5ba49ca91a81547
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Sat Oct 29 18:33:24 2011 -0200

    glx: don't leak driConfigs
    
    For dri, dri2 and driswrast.
    
    12,968 (584 direct, 12,384 indirect) bytes in 1 blocks are definitely lost in loss record 569 of 570
       at 0x4C2779D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
       by 0x7821E3B: driConcatConfigs (utils.c:560)
       by 0x7827CF2: dri_fill_in_modes (dri_screen.c:224)
       by 0x782831E: dri_init_screen_helper (dri_screen.c:405)
       by 0x7826C03: drisw_init_screen (drisw.c:266)
       by 0x782225F: driCreateNewScreen (drisw_util.c:69)
       by 0x4826E2: __glXDRIscreenProbe (glxdriswrast.c:451)
       by 0x4812FA: GlxExtensionInit (glxext.c:327)
       by 0x41FB14: InitExtensions (miinitext.c:471)
       by 0x568622: main (main.c:208)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/glx/glxdri.c b/glx/glxdri.c
index 244eac6..326f539 100644
--- a/glx/glxdri.c
+++ b/glx/glxdri.c
@@ -78,6 +78,7 @@ struct __GLXDRIscreen {
     const __DRIlegacyExtension *legacy;
     const __DRIcopySubBufferExtension *copySubBuffer;
     const __DRIswapControlExtension *swapControl;
+    const __DRIconfig **driConfigs;
 
 #ifdef __DRI_TEX_OFFSET
     const __DRItexOffsetExtension *texOffset;
@@ -585,6 +586,8 @@ static __GLXtextureFromPixmap __glXDRItextureFromPixmap = {
 static void
 __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 {
+    int i;
+
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
 
     screen->core->destroyScreen(screen->driScreen);
@@ -593,6 +596,12 @@ __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 
     __glXScreenDestroy(baseScreen);
 
+    if (screen->driConfigs) {
+	for (i = 0; screen->driConfigs[i] != NULL; i++)
+	    free((__DRIconfig **)screen->driConfigs[i]);
+	free(screen->driConfigs);
+    }
+
     free(screen);
 }
 
@@ -967,7 +976,6 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     Bool isCapable;
     size_t buffer_size;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    const __DRIconfig **driConfigs;
 
     if (!xf86LoaderCheckSymbol("DRIQueryDirectRenderingCapable") ||
 	!DRIQueryDirectRenderingCapable(pScreen, &isCapable) ||
@@ -1095,7 +1103,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 					   pSAREA,
 					   fd,
 					   loader_extensions,
-					   &driConfigs,
+					   &screen->driConfigs,
 					   screen);
 
     if (screen->driScreen == NULL) {
@@ -1105,7 +1113,8 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     }
 
     screen->base.fbconfigs = glxConvertConfigs(screen->core,
-					       driConfigs, GLX_WINDOW_BIT);
+					       screen->driConfigs,
+					       GLX_WINDOW_BIT);
 
     initializeExtensions(screen);
 
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index e872258..8187a3e 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -73,6 +73,7 @@ struct __GLXDRIscreen {
     const __DRIcopySubBufferExtension *copySubBuffer;
     const __DRIswapControlExtension *swapControl;
     const __DRItexBufferExtension *texBuffer;
+    const __DRIconfig **driConfigs;
 
     unsigned char glx_enable_bits[__GLX_EXT_BYTES];
 };
@@ -363,6 +364,8 @@ static __GLXtextureFromPixmap __glXDRItextureFromPixmap = {
 static void
 __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 {
+    int i;
+
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
 
     (*screen->core->destroyScreen)(screen->driScreen);
@@ -371,6 +374,12 @@ __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 
     __glXScreenDestroy(baseScreen);
 
+    if (screen->driConfigs) {
+	for (i = 0; screen->driConfigs[i] != NULL; i++)
+	    free((__DRIconfig **)screen->driConfigs[i]);
+	free(screen->driConfigs);
+    }
+
     free(screen);
 }
 
@@ -688,7 +697,6 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     __GLXDRIscreen *screen;
     size_t buffer_size;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    const __DRIconfig **driConfigs;
 
     screen = calloc(1, sizeof *screen);
     if (screen == NULL)
@@ -720,7 +728,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 	(*screen->dri2->createNewScreen)(pScreen->myNum,
 					 screen->fd,
 					 loader_extensions,
-					 &driConfigs,
+					 &screen->driConfigs,
 					 screen);
 
     if (screen->driScreen == NULL) {
@@ -731,7 +739,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 
     initializeExtensions(screen);
 
-    screen->base.fbconfigs = glxConvertConfigs(screen->core, driConfigs,
+    screen->base.fbconfigs = glxConvertConfigs(screen->core, screen->driConfigs,
 					       GLX_WINDOW_BIT |
 					       GLX_PIXMAP_BIT |
 					       GLX_PBUFFER_BIT);
diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index ed142c1..d064a05 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -74,6 +74,7 @@ struct __GLXDRIscreen {
     const __DRIswrastExtension *swrast;
     const __DRIcopySubBufferExtension *copySubBuffer;
     const __DRItexBufferExtension *texBuffer;
+    const __DRIconfig **driConfigs;
 };
 
 struct __GLXDRIcontext {
@@ -240,6 +241,8 @@ static __GLXtextureFromPixmap __glXDRItextureFromPixmap = {
 static void
 __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 {
+    int i;
+
     __GLXDRIscreen *screen = (__GLXDRIscreen *) baseScreen;
 
     (*screen->core->destroyScreen)(screen->driScreen);
@@ -248,6 +251,12 @@ __glXDRIscreenDestroy(__GLXscreen *baseScreen)
 
     __glXScreenDestroy(baseScreen);
 
+    if (screen->driConfigs) {
+	for (i = 0; screen->driConfigs[i] != NULL; i++)
+	    free((__DRIconfig **)screen->driConfigs[i]);
+	free(screen->driConfigs);
+    }
+
     free(screen);
 }
 
@@ -426,7 +435,6 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 {
     const char *driverName = "swrast";
     __GLXDRIscreen *screen;
-    const __DRIconfig **driConfigs;
 
     screen = calloc(1, sizeof *screen);
     if (screen == NULL)
@@ -450,7 +458,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     screen->driScreen =
 	(*screen->swrast->createNewScreen)(pScreen->myNum,
 					   loader_extensions,
-					   &driConfigs,
+					   &screen->driConfigs,
 					   screen);
 
     if (screen->driScreen == NULL) {
@@ -461,7 +469,7 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 
     initializeExtensions(screen);
 
-    screen->base.fbconfigs = glxConvertConfigs(screen->core, driConfigs,
+    screen->base.fbconfigs = glxConvertConfigs(screen->core, screen->driConfigs,
 					       GLX_WINDOW_BIT |
 					       GLX_PIXMAP_BIT |
 					       GLX_PBUFFER_BIT);
commit d26fae246d7c451b4d5ffe24fdb959d4bd00b107
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Tue Oct 25 14:56:35 2011 -0200

    glx: don't leak fbconfigs
    
    29,952 (208 direct, 29,744 indirect) bytes in 1 blocks are definitely lost in loss record 573 of 573
       at 0x4C2779D: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
       by 0x4829BC: createModeFromConfig (glxdricommon.c:131)
       by 0x482C09: glxConvertConfigs (glxdricommon.c:185)
       by 0x482788: __glXDRIscreenProbe (glxdriswrast.c:468)
       by 0x4812FA: GlxExtensionInit (glxext.c:327)
       by 0x41FB14: InitExtensions (miinitext.c:471)
       by 0x568636: main (main.c:208)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index ebb9747..928cf0c 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -419,6 +419,15 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
 
 void __glXScreenDestroy(__GLXscreen *screen)
 {
+    __GLXconfig *head, *next;
+
+    head = screen->fbconfigs;
+    while (head) {
+	next = head->next;
+	free(head);
+	head = next;
+    }
+
     free(screen->GLXvendor);
     free(screen->GLXextensions);
     free(screen->GLextensions);
commit 305a8bcb2fc6f87f8d891fcb774198b6fd118ee1
Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Thu Oct 20 17:39:29 2011 -0200

    glx: fix memory leak when destroying screen
    
    1,152 bytes in 1 blocks are definitely lost in loss record 536 of 575
       at 0x4C25E84: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
       by 0x483820: __glXScreenInit (glxscreens.c:357)
       by 0x48271C: __glXDRIscreenProbe (glxdriswrast.c:469)
       by 0x4812BE: GlxExtensionInit (glxext.c:327)
       by 0x41FB14: InitExtensions (miinitext.c:471)
       by 0x5685AE: main (main.c:208)
    
    Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index c4ad426..ebb9747 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -422,4 +422,5 @@ void __glXScreenDestroy(__GLXscreen *screen)
     free(screen->GLXvendor);
     free(screen->GLXextensions);
     free(screen->GLextensions);
+    free(screen->visuals);
 }


More information about the xorg-commit mailing list