Tk Source Code

View Ticket
Login
2026-10-08
19:42
Cherrypick fix for [6872190648]: Aqua: over-release in CreateCGImageFromDrawableRect() check-in: 2bf909da user: chrstphrchvz tags: bug-df4b603950-alt
2026-10-01
19:01 • Ticket [68721906] Aqua: over-release in CreateCGImageFromDrawableRect() status still Closed with 5 other changes artifact: 7515c4f2 user: marc_culler
18:59 • Closed ticket [68721906]. artifact: e380d04d user: marc_culler
18:55
Backport fix for [6872190648] - Aqua: over-release in CreateCGImageFromDrawableRect() - from Christopher Chavez check-in: ef133269 user: culler tags: core-9-0-branch
18:41
Merge fix for [6872190648] - Aqua: over-release in CreateCGImageFromDrawableRect() - from Christopher Chavez check-in: 2d659391 user: culler tags: trunk, main
18:37 • Ticket [68721906] Aqua: over-release in CreateCGImageFromDrawableRect() status still Open with 4 other changes artifact: 95c4cce9 user: marc_culler
17:39 • Ticket [68721906]: 3 changes artifact: 7e1c35cb user: serhiy.storchaka
2025-11-25
02:57
Fix [6872190648]: Aqua: over-release in CreateCGImageFromDrawableRect() closed check-in: b383b8f2 user: chrstphrchvz tags: bug-6872190648
02:52 • New ticket [68721906] Aqua: over-release in CreateCGImageFromDrawableRect(). artifact: ef1f59e7 user: chrstphrchvz

Ticket UUID: 6872190648bdeabaf61322b9d571ec70334ce021
Title: Aqua: over-release in CreateCGImageFromDrawableRect()
Type: Patch Version: core-9-0-branch
Submitter: chrstphrchvz Created on: 2025-11-25 02:52:28
Subsystem: 82. X11 Emulation Assigned To: marc_culler
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-01 19:01:42
Resolution: Accepted Closed By: marc_culler
    Closed on: 2026-10-01 19:01:42
Description:

CreateCGImageFromDrawableRect() incorrectly releases the colorspace object returned by CGImageGetColorSpace(image). The code examples at https://web.archive.org/web/20200219030756/http://blog.foundry376.com/2008/07/scaling-a-cgimage/#comment-200 contain the same problem.

I only notice this issue now because the colorspace used recently changed with [cd84376c]. Some colorspace objects do not respond to a release message (CFGetRetainCount() always returns 4294967295). Other colorspace objects have a reference count of only about 100 when Tk launches, so after enough calls to CreateCGImageFromDrawableRect() (specifically when downscaling a Retina source drawable), Tk will crash.

User Comments: marc_culler (claiming to be Marc Culler) added on 2026-10-01 19:01:42:
And removing that call to CGColorSpaceRelease( eliminates the crash.

I have merged the fix into 9.0 and 9.1.

marc_culler (claiming to be Marc Culler) added on 2026-10-01 18:37:56:
Yup.  That crashes on my macbook Air M3.

serhiy.storchaka added on 2026-10-01 17:39:15:

Still present in 9.0 and 9.1 (8.6 does not have this code). The fix in branch [bug-6872190648] is correct: CGImageGetColorSpace() follows the Get rule, so its result must not be released. The branch merges cleanly into main. Could someone with macOS test and merge it into core-9-0-branch and main?

A probable reproducer (untested, needs a Retina display): [.c postscript] grabs the embedded label with XGetImage(), which takes the downscaling path.

pack [canvas .c -width 200 -height 100]
label .c.l -text Hello
.c create window 100 50 -window .c.l
update
for {set i 1} {$i <= 1000} {incr i} {
    .c postscript
}
puts OK