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;
}
if (pAttr->pCursor) {
CursorPtr cursor;
if (!pWin->optional)
if (!MakeWindowOptional(pWin)) {
FreeResource(pWin->drawable.id, X11_RESTYPE_NONE);
return FALSE;
}
cursor = RefCursor(pAttr->pCursor);
CursorPtr cursor = RefCursor(pAttr->pCursor);
if (pWin->optional->cursor)
FreeCursor(pWin->optional->cursor, (Cursor) 0);
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/gc_priv.h"
#include "dix/window_priv.h"
#include "misc.h"
#include "os.h"
@ -270,8 +271,9 @@ ShapeRectangles(ClientPtr client, xShapeRectanglesReq *stuff)
return BadMatch;
srcRgn = RegionFromRects(nrects, prects, ctype);
if (!pWin->optional)
MakeWindowOptional(pWin);
if (!MakeWindowOptional(pWin))
return BadAlloc;
switch (stuff->destKind) {
case ShapeBounding:
destRgn = &pWin->optional->boundingShape;
@ -366,8 +368,9 @@ ShapeMask(ClientPtr client, xShapeMaskReq *stuff)
return BadAlloc;
}
if (!pWin->optional)
MakeWindowOptional(pWin);
if (!MakeWindowOptional(pWin))
return BadAlloc;
switch (stuff->destKind) {
case ShapeBounding:
destRgn = &pWin->optional->boundingShape;
@ -443,8 +446,9 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
rc = dixLookupWindow(&pDestWin, stuff->dest, client, DixSetAttrAccess);
if (rc != Success)
return rc;
if (!pDestWin->optional)
MakeWindowOptional(pDestWin);
if (!MakeWindowOptional(pDestWin))
return BadAlloc;
switch (stuff->destKind) {
case ShapeBounding:
createDefault = CreateBoundingShape;
@ -492,8 +496,9 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
else
srcRgn = (*createSrc) (pSrcWin);
if (!pDestWin->optional)
MakeWindowOptional(pDestWin);
if (!MakeWindowOptional(pDestWin))
return BadAlloc;
switch (stuff->destKind) {
case ShapeBounding:
destRgn = &pDestWin->optional->boundingShape;

View File

@ -96,6 +96,7 @@ SOFTWARE.
#include "dix/eventconvert.h"
#include "dix/exevents_priv.h"
#include "dix/input_priv.h"
#include "dix/window_priv.h"
#include "mi/mi_priv.h"
#include "inputstr.h"
@ -2733,7 +2734,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
{
InputClientsPtr others;
if (!pWin->optional && !MakeWindowOptional(pWin))
if (!MakeWindowOptional(pWin))
return BadAlloc;
others = AllocInputClient();
if (!others)

View File

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

View File

@ -55,6 +55,7 @@ SOFTWARE.
#include "dix/dix_priv.h"
#include "dix/dixgrabs_priv.h"
#include "dix/exevents_priv.h"
#include "dix/window_priv.h"
#include "os/auth.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);
return BadAlloc;
}
@ -660,8 +661,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
DeleteDetailFromMask(grab->modifiersDetail.pMask,
pMinuendGrab->modifiersDetail.
exact))
|| (!pNewGrab->window->optional &&
!MakeWindowOptional(pNewGrab->window))) {
|| (!MakeWindowOptional(pNewGrab->window))) {
FreeGrab(pNewGrab);
ok = FALSE;
}

View File

@ -51,6 +51,7 @@ SOFTWARE.
#include "dix/dix_priv.h"
#include "dix/property_priv.h"
#include "dix/window_priv.h"
#include "windowstr.h"
#include "propertyst.h"
@ -272,7 +273,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
rc = dixLookupProperty(&pProp, pWin, property, pClient, access_mode);
if (rc == BadMatch) { /* just add to list */
if (!pWin->optional && !MakeWindowOptional(pWin))
if (!MakeWindowOptional(pWin))
return BadAlloc;
pProp = dixAllocateObjectWithPrivates(PropertyRec, PRIVATE_PROPERTY);
if (!pProp)

View File

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

View File

@ -23,6 +23,7 @@
#include <dix-config.h>
#include "dix/dix_priv.h"
#include "dix/window_priv.h"
#include "render/picturestr_priv.h"
#include "xfixesint.h"
@ -642,8 +643,8 @@ ProcXFixesSetWindowShapeRegion(ClientPtr client)
pRegion = XFixesRegionCopy(pRegion);
if (!pRegion)
return BadAlloc;
if (!pWin->optional)
MakeWindowOptional(pWin);
if (!MakeWindowOptional(pWin))
return BadAlloc;
switch (stuff->destKind) {
default:
case ShapeBounding: