[PATCH 22/32] [libx11] xcms/LRGB: Add a label for freeing property_return.

Erkki Seppälä erkki.seppala at vincit.fi
Wed Jan 26 23:54:05 PST 2011


From: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira at nokia.com>

The rest of the code uses goto's to free memory allocated later
and prevent memory leaks, but there were several paths were
property_return was free'd just before a goto.

Reviewed-by: Erkki Seppälä <erkki.seppala at vincit.fi>
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira at nokia.com>
---
 src/xcms/LRGB.c |   26 ++++++++++----------------
 1 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/xcms/LRGB.c b/src/xcms/LRGB.c
index c1606be..4853483 100644
--- a/src/xcms/LRGB.c
+++ b/src/xcms/LRGB.c
@@ -594,8 +594,7 @@ LINEAR_RGB_InitSCCData(
 	     *		intensity2
 	     */
 	    if (nitems < 9) {
-		Xfree ((char *)property_return);
-		goto FreeSCCData;
+		goto Free_property_return;
 	    }
 	    count = 3;
 	    break;
@@ -611,8 +610,7 @@ LINEAR_RGB_InitSCCData(
 	     *		intensity2
 	     */
 	    if (nitems < 7) {
-		Xfree ((char *)property_return);
-		goto FreeSCCData;
+		goto Free_property_return;
 	    }
 	    count = 1;
 	    break;
@@ -627,14 +625,12 @@ LINEAR_RGB_InitSCCData(
 	     *		intensity2
 	     */
 	    if (nitems < 6) {
-		Xfree ((char *)property_return);
-		goto FreeSCCData;
+		goto Free_property_return;
 	    }
 	    count = 0;
 	    break;
 	  default:
-	    Xfree ((char *)property_return);
-	    goto FreeSCCData;
+	    goto Free_property_return;
 	}
 
 	/*
@@ -686,8 +682,7 @@ LINEAR_RGB_InitSCCData(
 	    /* Red Intensity Table */
 	    if (!(pScreenData->pRedTbl = (IntensityTbl *)
 		    Xcalloc (1, sizeof(IntensityTbl)))) {
-		XFree ((char * ) property_return);
-		goto FreeSCCData;
+		goto Free_property_return;
 	    }
 	    if (_XcmsGetTableType0(pScreenData->pRedTbl, format_return, &pChar,
 		    &nitems) == XcmsFailure) {
@@ -724,8 +719,7 @@ LINEAR_RGB_InitSCCData(
 	    /* Red Intensity Table */
 	    if (!(pScreenData->pRedTbl = (IntensityTbl *)
 		    Xcalloc (1, sizeof(IntensityTbl)))) {
-		XFree ((char * ) property_return);
-		goto FreeSCCData;
+		goto Free_property_return;
 	    }
 	    if (_XcmsGetTableType1(pScreenData->pRedTbl, format_return, &pChar,
 		    &nitems) == XcmsFailure) {
@@ -762,8 +756,7 @@ LINEAR_RGB_InitSCCData(
 		}
 	    }
 	} else {
-	    Xfree ((char *)property_return);
-	    goto FreeSCCData;
+	    goto Free_property_return;
 	}
 
 #ifdef ALLDEBUG
@@ -789,8 +782,6 @@ LINEAR_RGB_InitSCCData(
 #endif /* ALLDEBUG */
     }
 
-    Xfree ((char *)property_return);
-
     /* Free the old memory and use the new structure created. */
     LINEAR_RGB_FreeSCCData(pPerScrnInfo->screenData);
 
@@ -820,6 +811,9 @@ FreeRedTblElements:
 FreeRedTbl:
     Xfree((char *)pScreenData->pRedTbl);
 
+Free_property_return:
+    Xfree ((char *)property_return);
+
 FreeSCCData:
     Xfree((char *)pScreenData);
     pPerScrnInfo->state = XcmsInitNone;
-- 
1.7.0.4



More information about the xorg-devel mailing list