[PATCH:libX11 11/22] miRegionOp(): ensure region size is not updated if realloc fails
Alan Coopersmith
alan.coopersmith at oracle.com
Mon Aug 12 00:04:02 PDT 2013
This function performs operations on a region, and when finished,
checks to see if it should compact the rectangle list. If the
number of rectangles for which memory is allocated in the list is
more than twice the number used, it tries to shrink. realloc()
should not fail in this case, but if it does, might as well keep
the correct value for the number of allocated rectangles, so we
don't try to grow it unnecessarily later if adding to the region.
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
src/Region.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/Region.c b/src/Region.c
index 8946268..fcf53e6 100644
--- a/src/Region.c
+++ b/src/Region.c
@@ -980,11 +980,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