From 4d3d4a34ec7b72d6685917448261fd8ee9d300c9 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 8 May 2025 16:11:58 +0200 Subject: [PATCH] dix: region: turn xfreeData() into inline func and add checks For type-safety turn xfreeData() macro into an inline function. Also adding some checks against accidentially free()'ing global data. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/region.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dix/region.c b/dix/region.c index 2efc4de26..f45a56a9e 100644 --- a/dix/region.c +++ b/dix/region.c @@ -170,7 +170,12 @@ Equipment Corporation. // note: we really need to check for size, because when it's zero, then data // might point to RegionBrokenData (.data segment), which we must not free() // (this also can create analyzer false alarms) -#define xfreeData(reg) if ((reg)->data && (reg)->data->size) free((reg)->data) +static inline void xfreeData(RegionPtr reg) { + if (reg && reg->data && reg->data->size && + reg->data != &RegionBrokenData && + reg->data != &RegionEmptyData) + free(reg->data); +} #define RECTALLOC_BAIL(pReg,n,bail) \ if (!(pReg)->data || (((pReg)->data->numRects + (n)) > (pReg)->data->size)) \