From 5b541780c18923af44fa827441c6c2b418196e62 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 30 Sep 2024 17:52:07 +0200 Subject: [PATCH] dix: use dixDestroyPixmap() instead of direct driver call Direct calls to ScreenRec->DestroyPixmap() blocks cleaning up the wrapping jungle, so use the proper dix function instead. See: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1754 Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- dix/dispatch.c | 2 +- dix/gc.c | 20 +++++++++----------- dix/glyphcurs.c | 5 ++--- dix/pixmap.c | 7 +++---- dix/window.c | 18 +++++++++--------- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index 5f7cfe02d..efb17c734 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -1524,7 +1524,7 @@ ProcCreatePixmap(ClientPtr client) rc = XaceHookResourceAccess(client, stuff->pid, X11_RESTYPE_PIXMAP, pMap, X11_RESTYPE_NONE, NULL, DixCreateAccess); if (rc != Success) { - (*pDraw->pScreen->DestroyPixmap) (pMap); + dixDestroyPixmap(pMap, 0); return rc; } if (AddResource(stuff->pid, X11_RESTYPE_PIXMAP, (void *) pMap)) diff --git a/dix/gc.c b/dix/gc.c index 5f7535803..ab5844353 100644 --- a/dix/gc.c +++ b/dix/gc.c @@ -254,7 +254,7 @@ ChangeGC(ClientPtr client, GC * pGC, BITS32 mask, ChangeGCValPtr pUnion) else { pPixmap->refcnt++; if (!pGC->tileIsPixel) - (*pGC->pScreen->DestroyPixmap) (pGC->tile.pixmap); + dixDestroyPixmap(pGC->tile.pixmap, 0); pGC->tileIsPixel = FALSE; pGC->tile.pixmap = pPixmap; } @@ -271,7 +271,7 @@ ChangeGC(ClientPtr client, GC * pGC, BITS32 mask, ChangeGCValPtr pUnion) if (pPixmap) pPixmap->refcnt++; if (pGC->stipple) - (*pGC->pScreen->DestroyPixmap) (pGC->stipple); + dixDestroyPixmap(pGC->stipple, 0); pGC->stipple = pPixmap; } break; @@ -588,8 +588,7 @@ CreateDefaultTile(GCPtr pGC) (*pGC->pScreen->CreatePixmap) (pGC->pScreen, w, h, pGC->depth, 0); pgcScratch = GetScratchGC(pGC->depth, pGC->pScreen); if (!pTile || !pgcScratch) { - if (pTile) - (*pTile->drawable.pScreen->DestroyPixmap) (pTile); + dixDestroyPixmap(pTile, 0); if (pgcScratch) FreeScratchGC(pgcScratch); return FALSE; @@ -668,7 +667,7 @@ CopyGC(GC * pgcSrc, GC * pgcDst, BITS32 mask) break; } if (!pgcDst->tileIsPixel) - (*pgcDst->pScreen->DestroyPixmap) (pgcDst->tile.pixmap); + dixDestroyPixmap(pgcDst->tile.pixmap, 0); pgcDst->tileIsPixel = pgcSrc->tileIsPixel; pgcDst->tile = pgcSrc->tile; if (!pgcDst->tileIsPixel) @@ -680,7 +679,7 @@ CopyGC(GC * pgcSrc, GC * pgcDst, BITS32 mask) if (pgcDst->stipple == pgcSrc->stipple) break; if (pgcDst->stipple) - (*pgcDst->pScreen->DestroyPixmap) (pgcDst->stipple); + dixDestroyPixmap(pgcDst->stipple, 0); pgcDst->stipple = pgcSrc->stipple; if (pgcDst->stipple) pgcDst->stipple->refcnt++; @@ -775,9 +774,9 @@ FreeGC(void *value, XID gid) (*pGC->funcs->DestroyClip) (pGC); if (!pGC->tileIsPixel) - (*pGC->pScreen->DestroyPixmap) (pGC->tile.pixmap); + dixDestroyPixmap(pGC->tile.pixmap, 0); if (pGC->stipple) - (*pGC->pScreen->DestroyPixmap) (pGC->stipple); + dixDestroyPixmap(pGC->stipple, 0); if (pGC->funcs) (*pGC->funcs->DestroyGC) (pGC); @@ -885,7 +884,7 @@ CreateDefaultStipple(int screenNum) tmpval[2].val = FillSolid; pgcScratch = GetScratchGC(1, pScreen); if (!pgcScratch) { - (*pScreen->DestroyPixmap) (pScreen->defaultStipple); + dixDestroyPixmap(pScreen->defaultStipple, 0); return FALSE; } (void) ChangeGC(NullClient, pgcScratch, @@ -905,8 +904,7 @@ void FreeDefaultStipple(int screenNum) { ScreenPtr pScreen = screenInfo.screens[screenNum]; - - (*pScreen->DestroyPixmap) (pScreen->defaultStipple); + dixDestroyPixmap(pScreen->defaultStipple, 0); } int diff --git a/dix/glyphcurs.c b/dix/glyphcurs.c index 012af910e..5747d0b20 100644 --- a/dix/glyphcurs.c +++ b/dix/glyphcurs.c @@ -96,8 +96,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, CREATE_PIXMAP_USAGE_SCRATCH); pGC = GetScratchGC(1, pScreen); if (!ppix || !pGC) { - if (ppix) - (*pScreen->DestroyPixmap) (ppix); + dixDestroyPixmap(ppix, 0); if (pGC) FreeScratchGC(pGC); free(pbits); @@ -127,7 +126,7 @@ ServerBitsFromGlyph(FontPtr pfont, unsigned ch, CursorMetricPtr cm, XYPixmap, 1, pbits); *ppbits = (unsigned char *) pbits; FreeScratchGC(pGC); - (*pScreen->DestroyPixmap) (ppix); + dixDestroyPixmap(ppix, 0); return Success; } diff --git a/dix/pixmap.c b/dix/pixmap.c index 020ceb83a..f7812804a 100644 --- a/dix/pixmap.c +++ b/dix/pixmap.c @@ -63,7 +63,7 @@ GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth, if ((*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth, bitsPerPixel, devKind, pPixData)) return pPixmap; - (*pScreen->DestroyPixmap) (pPixmap); + dixDestroyPixmap(pPixmap, 0); } return NullPixmap; } @@ -73,9 +73,8 @@ void FreeScratchPixmapHeader(PixmapPtr pPixmap) { if (pPixmap) { - ScreenPtr pScreen = pPixmap->drawable.pScreen; pPixmap->devPrivate.ptr = NULL; /* help catch/avoid heap-use-after-free */ - (*pScreen->DestroyPixmap)(pPixmap); + dixDestroyPixmap(pPixmap, 0); } } @@ -151,7 +150,7 @@ PixmapPtr PixmapShareToSecondary(PixmapPtr pixmap, ScreenPtr secondary) ret = secondary->SetSharedPixmapBacking(spix, handle); if (ret == FALSE) { - secondary->DestroyPixmap(spix); + dixDestroyPixmap(spix, 0); return NULL; } diff --git a/dix/window.c b/dix/window.c index 6b7fc808e..672593512 100644 --- a/dix/window.c +++ b/dix/window.c @@ -1014,9 +1014,9 @@ FreeWindowResources(WindowPtr pWin) if (wInputShape(pWin)) RegionDestroy(wInputShape(pWin)); if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap) (pWin->border.pixmap); + dixDestroyPixmap(pWin->border.pixmap, 0); if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap) (pWin->background.pixmap); + dixDestroyPixmap(pWin->background.pixmap, 0); DeleteAllWindowProperties(pWin); /* We SHOULD check for an error value here XXX */ @@ -1195,7 +1195,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) borderRelative = TRUE; if (pixID == None) { if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap) (pWin->background.pixmap); + dixDestroyPixmap(pWin->background.pixmap, 0); if (!pWin->parent) SetRootWindowBackground(pWin, pScreen, &index2); else { @@ -1210,7 +1210,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) goto PatchUp; } if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap) (pWin->background.pixmap); + dixDestroyPixmap(pWin->background.pixmap, 0); if (!pWin->parent) SetRootWindowBackground(pWin, pScreen, &index2); else @@ -1229,7 +1229,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) goto PatchUp; } if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap) (pWin->background.pixmap); + dixDestroyPixmap(pWin->background.pixmap, 0); pWin->backgroundState = BackgroundPixmap; pWin->background.pixmap = pPixmap; pPixmap->refcnt++; @@ -1245,7 +1245,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) if (pWin->backgroundState == ParentRelative) borderRelative = TRUE; if (pWin->backgroundState == BackgroundPixmap) - (*pScreen->DestroyPixmap) (pWin->background.pixmap); + dixDestroyPixmap(pWin->background.pixmap, 0); pWin->backgroundState = BackgroundPixel; pWin->background.pixel = (CARD32) *pVlist; /* background pixel overrides background pixmap, @@ -1264,7 +1264,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) } if (pWin->parent->borderIsPixel == TRUE) { if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap) (pWin->border.pixmap); + dixDestroyPixmap(pWin->border.pixmap, 0); pWin->border = pWin->parent->border; pWin->borderIsPixel = TRUE; index2 = CWBorderPixel; @@ -1283,7 +1283,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) goto PatchUp; } if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap) (pWin->border.pixmap); + dixDestroyPixmap(pWin->border.pixmap, 0); pWin->borderIsPixel = FALSE; pWin->border.pixmap = pPixmap; pPixmap->refcnt++; @@ -1296,7 +1296,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client) break; case CWBorderPixel: if (pWin->borderIsPixel == FALSE) - (*pScreen->DestroyPixmap) (pWin->border.pixmap); + dixDestroyPixmap(pWin->border.pixmap, 0); pWin->borderIsPixel = TRUE; pWin->border.pixel = (CARD32) *pVlist; /* border pixel overrides border pixmap,