[PATCHv2 05/13] mi: fix memory leak in miInitVisuals

Tiago Vignatti tiago.vignatti at nokia.com
Mon Mar 28 06:14:27 PDT 2011


Free the pointers inside miInitVisuals, so the callers of this function
(fboverlay.c and fbscreen.c) don't need to worry with deallocation in the case
of failure.

Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
---
 fb/fbscreen.c |    4 ----
 mi/micmap.c   |    2 ++
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 2502efe..c5b35ac 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -225,11 +225,7 @@ fbFinishScreenInit(ScreenPtr	pScreen,
     rootdepth = 0;
     if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
 			&defaultVisual,((unsigned long)1<<(imagebpp-1)), 8))
-    {
-	free(visuals);
-	free(depths);
 	return FALSE;
-    }
     if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
 			rootdepth, ndepths, depths,
 			defaultVisual, nvisuals, visuals))
diff --git a/mi/micmap.c b/mi/micmap.c
index 41e0300..7448ef8 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -564,6 +564,8 @@ miInitVisuals(VisualPtr *visualp, DepthPtr *depthp, int *nvisualp,
 	{
 	    vid = malloc(nvtype * sizeof (VisualID));
 	    if (!vid) {
+	        free(depth);
+	        free(visual);
 		free(preferredCVCs);
 		return FALSE;
 	    }
-- 
1.7.0.4



More information about the xorg-devel mailing list