Avoid sequences of malloc(0) / free() by checking the length.

This has an impact on heap fragmentation.

Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
This commit is contained in:
Matthieu Herrb 2021-02-27 11:30:18 +01:00 committed by Peter Hutterer
parent 15a413e11d
commit b2d96b5cd4
1 changed files with 5 additions and 2 deletions

View File

@ -404,7 +404,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
int i;
BoxPtr pbox;
xRectangle *prect;
int numRects;
int numRects, regionnumrects;
/*
* Distance from screen to destination drawable, use this
@ -508,7 +508,10 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
gcmask |= GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin;
}
prect = xallocarray(RegionNumRects(prgn), sizeof(xRectangle));
regionnumrects = RegionNumRects(prgn);
if (regionnumrects == 0)
return;
prect = xallocarray(regionnumrects, sizeof(xRectangle));
if (!prect)
return;