Tk Source Code

View Ticket
Login
Ticket UUID: e02fc964f339d79f43b1d112831680ba03f48296
Title: leak in DrawDarkFocusRing()
Type: Patch Version: 8.6.10 and later
Submitter: chrstphrchvz Created on: 2022-02-02 05:15:52
Subsystem: 88. Themed Tk Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2022-02-24 12:32:04
Resolution: Fixed Closed By: chrstphrchvz
    Closed on: 2022-02-24 12:32:04
Description:

In DrawDarkFocusRing() (added to ttkMacOSXTheme.c in [b5497be5337d1820]), path should be released to prevent a leak:

diff --git macosx/ttkMacOSXTheme.c macosx/ttkMacOSXTheme.c
index 52880ef1c..ddaa2269e 100644
--- macosx/ttkMacOSXTheme.c
+++ macosx/ttkMacOSXTheme.c
@@ -1188,6 +1188,7 @@ static void DrawDarkFocusRing(
     CGPathRef path = CGPathCreateWithRoundedRect(insetBounds, 4, 4, NULL);
     CGContextBeginPath(context);
     CGContextAddPath(context, path);
+    CGPathRelease(path);
     CGContextAddRect(context, bounds);
     CGContextEOFillPath(context);
     CGContextRestoreGState(context);

User Comments: chrstphrchvz added on 2022-02-24 12:32:04:

Closing: patch was merged in [390768179e].


chrstphrchvz added on 2022-02-08 02:44:09:

Before applying the patch—applying the patch prevents the leak.


kevin_walzer added on 2022-02-08 02:21:52:
Is this leak you are describing before or after the patch is applied?

chrstphrchvz added on 2022-02-08 02:15:25:

This leak was found when Tcl and Tk were compiled using non-Xcode clang and -fsanitize=address -DPURIFY. By running this example:

$ ASAN_OPTIONS=malloc_context_size=100:detect_leaks=1 wish8.6 
% ::tk::unsupported::MacWindowStyle appearance . darkaqua
% pack [ttk::entry .e]

then clicking on the entry widget so that it draws a focus ring, and then closing wish, LeakSanitizer output will include a leak resembling the following:

Direct leak of 1536 byte(s) in 12 object(s) allocated from:
    #0 0x109088f70 in __sanitizer_mz_malloc+0xa0 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x47f70)
    #1 0x7ff818922ad5 in _malloc_zone_malloc+0x7c (libsystem_malloc.dylib:x86_64+0x1dad5)
    #2 0x7ff818b35053 in _CFRuntimeCreateInstance+0x243 (CoreFoundation:x86_64h+0x4053)
    #3 0x7ff81de1f96d in CGTypeCreateInstance+0x22 (CoreGraphics:x86_64h+0x296d)
    #4 0x7ff81dec97b0 in CGPathCreateWithRoundedRect+0xd3 (CoreGraphics:x86_64h+0xac7b0)
    #5 0x10ae2f8c1 in DrawDarkFocusRing ttkMacOSXTheme.c:1188
    #6 0x10ae3cfbd in EntryElementDraw ttkMacOSXTheme.c:1844
    #7 0x10abb4557 in Ttk_DrawElement ttkTheme.c:1118
    #8 0x10ab44685 in Ttk_DrawNodeList ttkLayout.c:1121
    #9 0x10ab43b2c in Ttk_DrawLayout ttkLayout.c:1133
    #10 0x10aadf6c2 in EntryDisplay ttkEntry.c:1209
    #11 0x10ac123a2 in DrawWidget ttkWidget.c:98
    #12 0x10dcd3cc9 in TclServiceIdle tclTimer.c:751
    #13 0x10db6cba3 in Tcl_DoOneEvent tclNotify.c:980
    #14 0x10ad52edb in -[TKContentView(TKWindowEvent) generateExposeEvents:] tkMacOSXWindowEvent.c:1196
    #15 0x10ad51480 in -[TKContentView(TKWindowEvent) drawRect:] tkMacOSXWindowEvent.c:1067
    #16 0x7ff81b73b2b2 in _NSViewDrawRect+0x78 (AppKit:x86_64+0x19b2b2)
    #17 0x7ff81be57ceb in -[NSView _recursive:displayRectIgnoringOpacity:inContext:stopAtLayerBackedViews:]+0x727 (AppKit:x86_64+0x8b7ceb)
    #18 0x7ff81b73a9b0 in -[NSView(NSLayerKitGlue) _drawViewBackingLayer:inContext:drawingHandler:]+0x2ea (AppKit:x86_64+0x19a9b0)
    #19 0x7ff81b73a5ef in -[NSView(NSLayerKitGlue) drawLayer:inContext:]+0x121 (AppKit:x86_64+0x19a5ef)
    #20 0x7ff81fc4e30d in CABackingStoreUpdate_+0x264 (QuartzCore:x86_64+0x2230d)
    #21 0x7ff81fcb33bc in invocation function for block in CA::Layer::display_()+0x34 (QuartzCore:x86_64+0x873bc)
    #22 0x7ff81fc4d69f in -[CALayer _display]+0x8db (QuartzCore:x86_64+0x2169f)
    #23 0x7ff81fc4c618 in CA::Layer::display_if_needed(CA::Transaction*)+0x362 (QuartzCore:x86_64+0x20618)
    #24 0x7ff81fd9c72a in CA::Context::commit_transaction(CA::Transaction*, double, double*)+0x2cc (QuartzCore:x86_64+0x17072a)
    #25 0x7ff81fc2e249 in CA::Transaction::commit()+0x2bf (QuartzCore:x86_64+0x2249)
    #26 0x7ff81b74b7d1 in __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke+0x11c (AppKit:x86_64+0x1ab7d1)
    #27 0x7ff81be940d3 in ___NSRunLoopObserverCreateWithHandler_block_invoke+0x28 (AppKit:x86_64+0x8f40d3)
    #28 0x7ff818bb0cb6 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+0x16 (CoreFoundation:x86_64h+0x7fcb6)
    #29 0x7ff818bb0b53 in __CFRunLoopDoObservers+0x21e (CoreFoundation:x86_64h+0x7fb53)
    #30 0x7ff818baffe6 in __CFRunLoopRun+0x348 (CoreFoundation:x86_64h+0x7efe6)
    #31 0x7ff818baf5dc in CFRunLoopRunSpecific+0x232 (CoreFoundation:x86_64h+0x7e5dc)
    #32 0x7ff8217ec4f0 in RunCurrentEventLoopInMode+0x123 (HIToolbox:x86_64+0x324f0)
    #33 0x7ff8217ec117 in ReceiveNextEventCommon+0x11b (HIToolbox:x86_64+0x32117)
    #34 0x7ff8217ebfe4 in _BlockUntilNextEventMatchingListInModeWithFilter+0x45 (HIToolbox:x86_64+0x31fe4)
    #35 0x7ff81b5ded87 in _DPSNextEvent+0x375 (AppKit:x86_64+0x3ed87)
    #36 0x7ff81b5dd3f3 in -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+0x582 (AppKit:x86_64+0x3d3f3)
    #37 0x10ad16ccf in TkMacOSXEventsSetupProc tkMacOSXNotify.c:477
    #38 0x10db6c40a in Tcl_DoOneEvent tclNotify.c:930
    #39 0x10a27b2af in Tk_MainLoop tkEvent.c:2109
    #40 0x10a349fe4 in Tk_MainEx tkMain.c:377
    #41 0x108c27c5e in main tkAppInit.c:93
    #42 0x1168384fd in start+0x1cd (dyld:x86_64+0x54fd)


kevin_walzer added on 2022-02-07 18:45:01:
Committed chavez_patches branch against trunk for testing. Test suite passes without issue. Please build and test; I will apply against core-8-6-branch if it looks OK to you.

kevin_walzer added on 2022-02-05 14:48:00:
Christopher, can you attach this as a plain-text patch so I can test it? It's not usable with the markup added.

Attachments: