From b2d96b5cd459963a9587ee9c86afc9266ba3d02b Mon Sep 17 00:00:00 2001 From: Matthieu Herrb Date: Sat, 27 Feb 2021 11:30:18 +0100 Subject: Avoid sequences of malloc(0) / free() by checking the length. This has an impact on heap fragmentation. Signed-off-by: Matthieu Herrb --- mi/miexpose.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mi/miexpose.c') diff --git a/mi/miexpose.c b/mi/miexpose.c index d84bb6a98..e54b18b30 100644 --- a/mi/miexpose.c +++ b/mi/miexpose.c @@ -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; -- cgit v1.2.3