exa: protect from allocation failure

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-02-24 13:51:52 +01:00
parent 8e80caa6f7
commit b3ef1fbbd3

View File

@ -371,7 +371,6 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
int src_off_x, src_off_y; int src_off_x, src_off_y;
int dst_off_x, dst_off_y; int dst_off_x, dst_off_y;
RegionPtr srcregion = NULL, dstregion = NULL; RegionPtr srcregion = NULL, dstregion = NULL;
xRectangle *rects;
Bool ret = TRUE; Bool ret = TRUE;
/* avoid doing copy operations if no boxes */ /* avoid doing copy operations if no boxes */
@ -384,8 +383,7 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y); exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y);
exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y); exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y);
rects = calloc(nbox, sizeof(xRectangle)); xRectangle *rects = calloc(nbox, sizeof(xRectangle));
if (rects) { if (rects) {
int i; int i;
int ordering; int ordering;
@ -614,7 +612,6 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
{ {
ExaScreenPriv(pDrawable->pScreen); ExaScreenPriv(pDrawable->pScreen);
int i; int i;
xRectangle *prect;
/* If we can't reuse the current GC as is, don't bother accelerating the /* If we can't reuse the current GC as is, don't bother accelerating the
* points. * points.
@ -624,7 +621,9 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return; return;
} }
prect = calloc(npt, sizeof(xRectangle)); xRectangle *prect = calloc(npt, sizeof(xRectangle));
if (!prect)
return;
for (i = 0; i < npt; i++) { for (i = 0; i < npt; i++) {
prect[i].x = ppt[i].x; prect[i].x = ppt[i].x;
prect[i].y = ppt[i].y; prect[i].y = ppt[i].y;
@ -649,7 +648,6 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
DDXPointPtr ppt) DDXPointPtr ppt)
{ {
ExaScreenPriv(pDrawable->pScreen); ExaScreenPriv(pDrawable->pScreen);
xRectangle *prect;
int x1, x2, y1, y2; int x1, x2, y1, y2;
int i; int i;
@ -665,7 +663,9 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
return; return;
} }
prect = calloc(npt - 1, sizeof(xRectangle)); xRectangle *prect = calloc(npt - 1, sizeof(xRectangle));
if (!prect)
return;
x1 = ppt[0].x; x1 = ppt[0].x;
y1 = ppt[0].y; y1 = ppt[0].y;
/* If we have any non-horizontal/vertical, fall back. */ /* If we have any non-horizontal/vertical, fall back. */
@ -718,7 +718,7 @@ static void
exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg) exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
{ {
ExaScreenPriv(pDrawable->pScreen); ExaScreenPriv(pDrawable->pScreen);
xRectangle *prect; ;
int i; int i;
/* Don't try to do wide lines or non-solid fill style. */ /* Don't try to do wide lines or non-solid fill style. */
@ -736,7 +736,9 @@ exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
} }
} }
prect = calloc((unsigned int)nseg, sizeof(xRectangle)); xRectangle *prect = calloc((unsigned int)nseg, sizeof(xRectangle));
if (!prect)
return;
for (i = 0; i < nseg; i++) { for (i = 0; i < nseg; i++) {
if (pSeg[i].x1 < pSeg[i].x2) { if (pSeg[i].x1 < pSeg[i].x2) {
prect[i].x = pSeg[i].x1; prect[i].x = pSeg[i].x1;