[PATCH:libX11 09/12] Region.c: ensure region size is updated correctly if realloc fails

Alan Coopersmith alan.coopersmith at oracle.com
Sat Aug 10 13:55:06 PDT 2013


Don't want later users of the function to think there's more or less
memory allocated than there really is.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/Region.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/Region.c b/src/Region.c
index d3d431a..ece9695 100644
--- a/src/Region.c
+++ b/src/Region.c
@@ -525,6 +525,7 @@ miRegionCopy(
 					 rgn->numRects * (sizeof(BOX)));
 		if (! dstrgn->rects) {
 		    Xfree(prevRects);
+		    dstrgn->size = 0;
 		    return;
 		}
             }
@@ -978,11 +979,12 @@ miRegionOp(
 	if (REGION_NOT_EMPTY(newReg))
 	{
 	    BoxPtr prev_rects = newReg->rects;
-	    newReg->size = newReg->numRects;
 	    newReg->rects = Xrealloc (newReg->rects,
-				      sizeof(BoxRec) * newReg->size);
+				      sizeof(BoxRec) * newReg->numRects);
 	    if (! newReg->rects)
 		newReg->rects = prev_rects;
+	    else
+		newReg->size = newReg->numRects;
 	}
 	else
 	{
-- 
1.7.9.2



More information about the xorg-devel mailing list