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 3d53ec7ed3
commit 28b7bdf84a
8 changed files with 35 additions and 28 deletions

View File

@ -498,13 +498,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

@ -33,6 +33,7 @@ in this Software without prior written authorization from The Open Group.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/gc_priv.h" #include "dix/gc_priv.h"
#include "dix/window_priv.h"
#include "misc.h" #include "misc.h"
#include "os.h" #include "os.h"
@ -270,8 +271,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;
@ -366,8 +368,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;
@ -443,8 +446,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;
@ -492,8 +496,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

@ -96,6 +96,7 @@ SOFTWARE.
#include "dix/eventconvert.h" #include "dix/eventconvert.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/window_priv.h"
#include "mi/mi_priv.h" #include "mi/mi_priv.h"
#include "inputstr.h" #include "inputstr.h"
@ -2733,7 +2734,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

@ -126,6 +126,7 @@ Equipment Corporation.
#include "dix/extension_priv.h" #include "dix/extension_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/reqhandlers_priv.h" #include "dix/reqhandlers_priv.h"
#include "dix/window_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "os/fmt.h" #include "os/fmt.h"
@ -4588,7 +4589,7 @@ EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
} }
} }
check = 0; check = 0;
if (!pWin->optional && !MakeWindowOptional(pWin)) if (!MakeWindowOptional(pWin))
return BadAlloc; return BadAlloc;
others = malloc(sizeof(OtherClients)); others = malloc(sizeof(OtherClients));
if (!others) if (!others)
@ -4647,7 +4648,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

@ -55,6 +55,7 @@ SOFTWARE.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/dixgrabs_priv.h" #include "dix/dixgrabs_priv.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/window_priv.h"
#include "os/auth.h" #include "os/auth.h"
#include "os/client_priv.h" #include "os/client_priv.h"
@ -561,7 +562,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;
} }
@ -660,8 +661,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

@ -51,6 +51,7 @@ SOFTWARE.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/property_priv.h" #include "dix/property_priv.h"
#include "dix/window_priv.h"
#include "windowstr.h" #include "windowstr.h"
#include "propertyst.h" #include "propertyst.h"
@ -272,7 +273,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

@ -1338,7 +1338,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;
} }
@ -1350,7 +1350,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;
} }
@ -1451,7 +1451,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;
} }
@ -3447,7 +3447,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

@ -23,6 +23,7 @@
#include <dix-config.h> #include <dix-config.h>
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/window_priv.h"
#include "render/picturestr_priv.h" #include "render/picturestr_priv.h"
#include "xfixesint.h" #include "xfixesint.h"
@ -642,8 +643,8 @@ ProcXFixesSetWindowShapeRegion(ClientPtr client)
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: