diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-02-11 15:20:49 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-02-11 15:20:49 (GMT) |
commit | f06792d283d6ba8358c7ebfe4ac6685c91e2774a (patch) | |
tree | 4a5ab370ea775db8028647ae84f92229b05a6256 /macosx | |
parent | 17a2a32f5d8320a600f7c686251597cef4705b9a (diff) | |
parent | f61e0446947534fe6cacb522964ef568187f2e69 (diff) | |
download | tk-f06792d283d6ba8358c7ebfe4ac6685c91e2774a.zip tk-f06792d283d6ba8358c7ebfe4ac6685c91e2774a.tar.gz tk-f06792d283d6ba8358c7ebfe4ac6685c91e2774a.tar.bz2 |
Memory leak patches from Christopher Chavez (rebased to 8.6)
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/tkMacOSXImage.c | 41 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 11 | ||||
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 1 |
3 files changed, 34 insertions, 19 deletions
diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 9a1ea45..fc0ffdf 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -144,25 +144,28 @@ TkMacOSXCreateCGImageWithXImage( bitsPerComponent = 1; bitsPerPixel = 1; - if (image->bitmap_bit_order != MSBFirst) { - char *srcPtr = image->data + image->xoffset; - char *endPtr = srcPtr + len; - char *destPtr = (data = (char *)ckalloc(len)); + data = (char *)ckalloc(len); + if (data) { + if (image->bitmap_bit_order != MSBFirst) { + char *srcPtr = image->data + image->xoffset; + char *endPtr = srcPtr + len; + char *destPtr = data; - while (srcPtr < endPtr) { - *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; + while (srcPtr < endPtr) { + *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; + } + } else { + memcpy(data, image->data + image->xoffset, len); } - } else { - data = (char *)memcpy(ckalloc(len), image->data + image->xoffset, len); - } - if (data) { provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { + if (!provider) { + ckfree(data); + } img = CGImageMaskCreate(image->width, image->height, bitsPerComponent, bitsPerPixel, image->bytes_per_line, provider, decode, 0); + CGDataProviderRelease(provider); } } else if ((image->format == ZPixmap) && (image->bits_per_pixel == 32)) { @@ -170,8 +173,6 @@ TkMacOSXCreateCGImageWithXImage( * Color image */ - CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); - if (image->width == 0 && image->height == 0) { /* @@ -180,19 +181,22 @@ TkMacOSXCreateCGImageWithXImage( return NULL; } + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); bitsPerComponent = 8; bitsPerPixel = 32; bitmapInfo = kCGBitmapByteOrder32Big | alphaInfo; - data = (char *)memcpy(ckalloc(len), image->data + image->xoffset, len); + data = (char *)ckalloc(len); if (data) { + memcpy(data, image->data + image->xoffset, len); provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { + if (!provider) { + ckfree(data); + } img = CGImageCreate(image->width, image->height, bitsPerComponent, bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo, provider, decode, 0, kCGRenderingIntentDefault); - CFRelease(provider); + CGDataProviderRelease(provider); } if (colorspace) { CFRelease(colorspace); @@ -650,6 +654,7 @@ CreateCGImageFromDrawableRect( CGImageRef cg_image = NULL, result = NULL; if (mac_drawable->flags & TK_IS_PIXMAP) { cg_context = TkMacOSXGetCGContextForDrawable(drawable); + CGContextRetain(cg_context); } else { NSView *view = TkMacOSXGetNSViewForDrawable(mac_drawable); if (view == nil) { diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 7b06200..9bcbd58 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -1122,6 +1122,13 @@ TkWmDeadWindow( * preventing zombies is to set the key window to nil. */ + + /* + * Fix bug 5692042764: + * set tkEventTarget to NULL when there is no window to send Tk events to. + */ + TkWindow *newTkEventTarget = NULL; + for (NSWindow *w in [NSApp orderedWindows]) { TkWindow *winPtr2 = TkMacOSXGetTkWindow(w); BOOL isOnScreen; @@ -1134,11 +1141,13 @@ TkWmDeadWindow( wmPtr2->hints.initial_state != WithdrawnState); if (w != deadNSWindow && isOnScreen && [w canBecomeKeyWindow]) { [w makeKeyAndOrderFront:NSApp]; - [NSApp setTkEventTarget:TkMacOSXGetTkWindow(w)]; + newTkEventTarget = TkMacOSXGetTkWindow(w); break; } } + [NSApp setTkEventTarget:newTkEventTarget]; + /* * Prevent zombies on systems with a TouchBar. */ diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index 52880ef..ddaa226 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/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); |