Attachment "0004-Make-TkSetRegion-safer.patch" to
ticket [f9eddb54]
added by
chrstphrchvz
2023-07-16 12:03:46.
From 1ca61bbebf0cc5c0569b91866519a3b59b1c961f Mon Sep 17 00:00:00 2001
From: Christopher Chavez <[email protected]>
Date: Sun, 16 Jul 2023 00:19:13 -0500
Subject: [PATCH 4/6] Make TkSetRegion() safer
---
xlib/xgc.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git xlib/xgc.c xlib/xgc.c
index b79b13555..13d08cd3d 100644
--- xlib/xgc.c
+++ xlib/xgc.c
@@ -49,6 +49,8 @@ static TkpClipMask *AllocClipMask(GC gc) {
if (clip_mask == NULL) {
clip_mask = (TkpClipMask *)ckalloc(sizeof(TkpClipMask));
gc->clip_mask = (Pixmap) clip_mask;
+ } else if (clip_mask->type == TKP_CLIP_REGION) {
+ TkDestroyRegion(clip_mask->value.region);
}
clip_mask->type = TKP_CLIP_PIXMAP;
clip_mask->value.pixmap = None;
@@ -76,6 +78,9 @@ static void FreeClipMask(GC gc) {
if (clip_mask == NULL) {
return;
}
+ if (clip_mask->type == TKP_CLIP_REGION) {
+ TkDestroyRegion(clip_mask->value.region);
+ }
ckfree(clip_mask);
gc->clip_mask = None;
}
@@ -431,8 +436,8 @@ XSetClipOrigin(
*
* Sets the clipping region/pixmap for a GC.
*
- * Note that unlike the Xlib equivalent, it is not safe to delete the
- * region after setting it into the GC (except on Mac OS X). The only
+ * Like the Xlib equivalent, it is safe to delete the
+ * region after setting it into the GC. The only
* uses of TkSetRegion are currently in DisplayFrame and in
* ImgPhotoDisplay, which use the GC immediately.
*
@@ -459,7 +464,8 @@ TkSetRegion(
TkpClipMask *clip_mask = AllocClipMask(gc);
clip_mask->type = TKP_CLIP_REGION;
- clip_mask->value.region = r;
+ clip_mask->value.region = TkCreateRegion();
+ TkpCopyRegion(clip_mask->value.region, r);
}
return Success;
}
--
2.39.2 (Apple Git-144)