From 22a614a05c951135531de00b5fe93bba1b901316 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 2 Oct 2024 22:20:22 +0200 Subject: [PATCH] (!1711) exa: simplify CreatePixmap()/DestroyPixmap() handlers error pathes Instead of complex wrap/unwrap trickery in the error path, just protect the DestroyPixmap() handlers from half-initialized state. This not just makes the code flow simpler and easier to understand, but also clears the road for decoupling the extension specific pixmap destructor logic from the ScreenRec proc vectors (*1). *1) see: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1755 Signed-off-by: Enrico Weigelt, metux IT consult --- exa/exa_classic.c | 13 +++++-------- exa/exa_driver.c | 8 ++++---- exa/exa_mixed.c | 3 +++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/exa/exa_classic.c b/exa/exa_classic.c index 7f93f1e3d..7be8b9fa9 100644 --- a/exa/exa_classic.c +++ b/exa/exa_classic.c @@ -96,10 +96,7 @@ exaCreatePixmap_classic(ScreenPtr pScreen, int w, int h, int depth, pExaPixmap->fb_size = pExaPixmap->fb_pitch * h; if (pExaPixmap->fb_pitch > 131071) { - swap(pExaScr, pScreen, DestroyPixmap); - if (pScreen->DestroyPixmap) - pScreen->DestroyPixmap(pPixmap); - swap(pExaScr, pScreen, DestroyPixmap); + dixDestroyPixmap(pPixmap, 0); return NULL; } @@ -109,10 +106,7 @@ exaCreatePixmap_classic(ScreenPtr pScreen, int w, int h, int depth, pScreen, pPixmap); if (pExaPixmap->pDamage == NULL) { - swap(pExaScr, pScreen, DestroyPixmap); - if (pScreen->DestroyPixmap) - pScreen->DestroyPixmap(pPixmap); - swap(pExaScr, pScreen, DestroyPixmap); + dixDestroyPixmap(pPixmap, 0); return NULL; } @@ -218,6 +212,8 @@ exaDestroyPixmap_classic(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) // we're called on an error path + goto out; exaDestroyPixmap(pPixmap); @@ -235,6 +231,7 @@ exaDestroyPixmap_classic(PixmapPtr pPixmap) RegionUninit(&pExaPixmap->validFB); } +out: swap(pExaScr, pScreen, DestroyPixmap); if (pScreen->DestroyPixmap) ret = pScreen->DestroyPixmap(pPixmap); diff --git a/exa/exa_driver.c b/exa/exa_driver.c index 17106fcb9..1896d87fe 100644 --- a/exa/exa_driver.c +++ b/exa/exa_driver.c @@ -98,10 +98,7 @@ exaCreatePixmap_driver(ScreenPtr pScreen, int w, int h, int depth, } if (!pExaPixmap->driverPriv) { - swap(pExaScr, pScreen, DestroyPixmap); - if (pScreen->DestroyPixmap) - pScreen->DestroyPixmap(pPixmap); - swap(pExaScr, pScreen, DestroyPixmap); + dixDestroyPixmap(pPixmap, 0); return NULL; } @@ -196,6 +193,8 @@ exaDestroyPixmap_driver(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) // we're called on an error path + goto out; exaDestroyPixmap(pPixmap); @@ -204,6 +203,7 @@ exaDestroyPixmap_driver(PixmapPtr pPixmap) pExaPixmap->driverPriv = NULL; } +out: swap(pExaScr, pScreen, DestroyPixmap); if (pScreen->DestroyPixmap) ret = pScreen->DestroyPixmap(pPixmap); diff --git a/exa/exa_mixed.c b/exa/exa_mixed.c index 7138f9b30..68f23beb5 100644 --- a/exa/exa_mixed.c +++ b/exa/exa_mixed.c @@ -249,6 +249,8 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) + goto out; // we're called on an error path exaDestroyPixmap(pPixmap); @@ -266,6 +268,7 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap) } } +out: swap(pExaScr, pScreen, DestroyPixmap); if (pScreen->DestroyPixmap) ret = pScreen->DestroyPixmap(pPixmap);