From 50ebc2464ceb4c7dafe8c97a8263cee08453854e 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 006b3862d..eff3bb811 100644 --- a/exa/exa_classic.c +++ b/exa/exa_classic.c @@ -98,10 +98,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; } @@ -111,10 +108,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; } @@ -220,6 +214,8 @@ exaDestroyPixmap_classic(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) // we're called on an error path + goto out; exaDestroyPixmap(pPixmap); @@ -237,6 +233,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 f7c2e5d28..1be0606f0 100644 --- a/exa/exa_driver.c +++ b/exa/exa_driver.c @@ -100,10 +100,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; } @@ -198,6 +195,8 @@ exaDestroyPixmap_driver(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) // we're called on an error path + goto out; exaDestroyPixmap(pPixmap); @@ -206,6 +205,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 cda15e7f7..0606cfde9 100644 --- a/exa/exa_mixed.c +++ b/exa/exa_mixed.c @@ -251,6 +251,8 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap) if (pPixmap->refcnt == 1) { ExaPixmapPriv(pPixmap); + if (!pExaPixmap) + goto out; // we're called on an error path exaDestroyPixmap(pPixmap); @@ -268,6 +270,7 @@ exaDestroyPixmap_mixed(PixmapPtr pPixmap) } } +out: swap(pExaScr, pScreen, DestroyPixmap); if (pScreen->DestroyPixmap) ret = pScreen->DestroyPixmap(pPixmap);