dix: clean up MakeWindowOptional() calls and add alloc fault checks

a) no need to checking for win->optional == NULL before calling
   MakeWindowOptional(), because it checks itself
   (except some cases where it's presence has it's own semantics,
   or prevent unnecessary allocations)
b) lots of call sites didn't check for allocation failure.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-03-14 13:54:42 +01:00
parent 8966b04224
commit 43dd9e5f43
8 changed files with 29 additions and 28 deletions

View File

@ -495,13 +495,11 @@ CreateSaverWindow(ScreenPtr pScreen)
mask |= CWBorderPixmap; mask |= CWBorderPixmap;
} }
if (pAttr->pCursor) { if (pAttr->pCursor) {
CursorPtr cursor; if (!MakeWindowOptional(pWin)) {
if (!pWin->optional) FreeResource(pWin->drawable.id, X11_RESTYPE_NONE);
if (!MakeWindowOptional(pWin)) { return FALSE;
FreeResource(pWin->drawable.id, X11_RESTYPE_NONE); }
return FALSE; CursorPtr cursor = RefCursor(pAttr->pCursor);
}
cursor = RefCursor(pAttr->pCursor);
if (pWin->optional->cursor) if (pWin->optional->cursor)
FreeCursor(pWin->optional->cursor, (Cursor) 0); FreeCursor(pWin->optional->cursor, (Cursor) 0);
pWin->optional->cursor = cursor; pWin->optional->cursor = cursor;

View File

@ -268,8 +268,9 @@ ShapeRectangles(ClientPtr client, xShapeRectanglesReq *stuff)
return BadMatch; return BadMatch;
srcRgn = RegionFromRects(nrects, prects, ctype); srcRgn = RegionFromRects(nrects, prects, ctype);
if (!pWin->optional) if (!MakeWindowOptional(pWin))
MakeWindowOptional(pWin); return BadAlloc;
switch (stuff->destKind) { switch (stuff->destKind) {
case ShapeBounding: case ShapeBounding:
destRgn = &pWin->optional->boundingShape; destRgn = &pWin->optional->boundingShape;
@ -364,8 +365,9 @@ ShapeMask(ClientPtr client, xShapeMaskReq *stuff)
return BadAlloc; return BadAlloc;
} }
if (!pWin->optional) if (!MakeWindowOptional(pWin))
MakeWindowOptional(pWin); return BadAlloc;
switch (stuff->destKind) { switch (stuff->destKind) {
case ShapeBounding: case ShapeBounding:
destRgn = &pWin->optional->boundingShape; destRgn = &pWin->optional->boundingShape;
@ -441,8 +443,9 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess); rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
if (!pDestWin->optional) if (!MakeWindowOptional(pDestWin))
MakeWindowOptional(pDestWin); return BadAlloc;
switch (stuff->destKind) { switch (stuff->destKind) {
case ShapeBounding: case ShapeBounding:
createDefault = CreateBoundingShape; createDefault = CreateBoundingShape;
@ -490,8 +493,9 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
else else
srcRgn = (*createSrc) (pSrcWin); srcRgn = (*createSrc) (pSrcWin);
if (!pDestWin->optional) if (!MakeWindowOptional(pDestWin))
MakeWindowOptional(pDestWin); return BadAlloc;
switch (stuff->destKind) { switch (stuff->destKind) {
case ShapeBounding: case ShapeBounding:
destRgn = &pDestWin->optional->boundingShape; destRgn = &pDestWin->optional->boundingShape;

View File

@ -2740,7 +2740,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
{ {
InputClientsPtr others; InputClientsPtr others;
if (!pWin->optional && !MakeWindowOptional(pWin)) if (!MakeWindowOptional(pWin))
return BadAlloc; return BadAlloc;
others = AllocInputClient(); others = AllocInputClient();
if (!others) if (!others)

View File

@ -4587,7 +4587,7 @@ XRetCode EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
} }
} }
check = 0; check = 0;
if (!pWin->optional && !MakeWindowOptional(pWin)) if (!MakeWindowOptional(pWin))
return BadAlloc; return BadAlloc;
others = calloc(1, sizeof(OtherClients)); others = calloc(1, sizeof(OtherClients));
if (!others) if (!others)
@ -4646,7 +4646,7 @@ EventSuppressForWindow(WindowPtr pWin, ClientPtr client,
} }
} }
else { else {
if (!pWin->optional && !MakeWindowOptional(pWin)) { if (!MakeWindowOptional(pWin)) {
if (pWin->dontPropagate) if (pWin->dontPropagate)
DontPropagateRefCnts[pWin->dontPropagate]++; DontPropagateRefCnts[pWin->dontPropagate]++;
return BadAlloc; return BadAlloc;

View File

@ -564,7 +564,7 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
} }
} }
if (!pGrab->window->optional && !MakeWindowOptional(pGrab->window)) { if (!MakeWindowOptional(pGrab->window)) {
FreeGrab(pGrab); FreeGrab(pGrab);
return BadAlloc; return BadAlloc;
} }
@ -663,8 +663,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
DeleteDetailFromMask(grab->modifiersDetail.pMask, DeleteDetailFromMask(grab->modifiersDetail.pMask,
pMinuendGrab->modifiersDetail. pMinuendGrab->modifiersDetail.
exact)) exact))
|| (!pNewGrab->window->optional && || (!MakeWindowOptional(pNewGrab->window))) {
!MakeWindowOptional(pNewGrab->window))) {
FreeGrab(pNewGrab); FreeGrab(pNewGrab);
ok = FALSE; ok = FALSE;
} }

View File

@ -316,7 +316,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
rc = dixLookupProperty(&pProp, pWin, property, pClient, access_mode); rc = dixLookupProperty(&pProp, pWin, property, pClient, access_mode);
if (rc == BadMatch) { /* just add to list */ if (rc == BadMatch) { /* just add to list */
if (!pWin->optional && !MakeWindowOptional(pWin)) if (!MakeWindowOptional(pWin))
return BadAlloc; return BadAlloc;
pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY); pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
if (!pProp) if (!pProp)

View File

@ -1317,7 +1317,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
break; break;
case CWBackingPlanes: case CWBackingPlanes:
if (pWin->optional || ((CARD32) *pVlist != (CARD32) ~0L)) { if (pWin->optional || ((CARD32) *pVlist != (CARD32) ~0L)) {
if (!pWin->optional && !MakeWindowOptional(pWin)) { if (!MakeWindowOptional(pWin)) {
error = BadAlloc; error = BadAlloc;
goto PatchUp; goto PatchUp;
} }
@ -1329,7 +1329,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
break; break;
case CWBackingPixel: case CWBackingPixel:
if (pWin->optional || (CARD32) *pVlist) { if (pWin->optional || (CARD32) *pVlist) {
if (!pWin->optional && !MakeWindowOptional(pWin)) { if (!MakeWindowOptional(pWin)) {
error = BadAlloc; error = BadAlloc;
goto PatchUp; goto PatchUp;
} }
@ -1430,7 +1430,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
for (pChild = pWin->firstChild; pChild; for (pChild = pWin->firstChild; pChild;
pChild = pChild->nextSib) { pChild = pChild->nextSib) {
if (!pChild->optional && !MakeWindowOptional(pChild)) { if (!MakeWindowOptional(pChild)) {
error = BadAlloc; error = BadAlloc;
goto PatchUp; goto PatchUp;
} }
@ -3430,7 +3430,7 @@ ChangeWindowDeviceCursor(WindowPtr pWin, DeviceIntPtr pDev, CursorPtr pCursor)
ScreenPtr pScreen; ScreenPtr pScreen;
WindowPtr pChild; WindowPtr pChild;
if (!pWin->optional && !MakeWindowOptional(pWin)) if (!MakeWindowOptional(pWin))
return BadAlloc; return BadAlloc;
/* 1) Check if window has device cursor set /* 1) Check if window has device cursor set

View File

@ -658,8 +658,8 @@ SingleXFixesSetWindowShapeRegion(ClientPtr client, xXFixesSetWindowShapeRegionRe
pRegion = XFixesRegionCopy(pRegion); pRegion = XFixesRegionCopy(pRegion);
if (!pRegion) if (!pRegion)
return BadAlloc; return BadAlloc;
if (!pWin->optional) if (!MakeWindowOptional(pWin))
MakeWindowOptional(pWin); return BadAlloc;
switch (stuff->destKind) { switch (stuff->destKind) {
default: default:
case ShapeBounding: case ShapeBounding: