Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See Git checking messages for full history.
- Linux: introduce an XCB-powered backend stack with a factory in ``mss.linux`` while keeping the Xlib code as a fallback (#425)
- Linux: add the XShmGetImage backend with automatic XGetImage fallback and explicit status reporting (#431)
- Windows: improve error checking and messages for Win32 API calls (#448)
- Mac: fix memory leak (#450, #453)
- :heart: contributors: @jholveck

## 10.1.0 (2025-08-16)
Expand Down
35 changes: 22 additions & 13 deletions src/mss/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
import ctypes
import ctypes.util
import sys
from ctypes import POINTER, Structure, c_double, c_float, c_int32, c_ubyte, c_uint32, c_uint64, c_void_p
from ctypes import (
POINTER,
Structure,
c_double,
c_float,
c_int32,
c_long,
c_size_t,
c_ubyte,
c_uint32,
c_void_p,
)
from platform import mac_ver
from typing import TYPE_CHECKING, Any

Expand Down Expand Up @@ -75,17 +86,16 @@ def __repr__(self) -> str:
# Syntax: cfunction: (attr, argtypes, restype)
"CGDataProviderCopyData": ("core", [c_void_p], c_void_p),
"CGDisplayBounds": ("core", [c_uint32], CGRect),
"CGDisplayRotation": ("core", [c_uint32], c_float),
"CFDataGetBytePtr": ("core", [c_void_p], c_void_p),
"CFDataGetLength": ("core", [c_void_p], c_uint64),
"CFRelease": ("core", [c_void_p], c_void_p),
"CGDataProviderRelease": ("core", [c_void_p], c_void_p),
"CGDisplayRotation": ("core", [c_uint32], c_double),
"CFDataGetBytePtr": ("core", [c_void_p], POINTER(c_ubyte)),
"CFDataGetLength": ("core", [c_void_p], c_long),
"CFRelease": ("core", [c_void_p], None),
"CGGetActiveDisplayList": ("core", [c_uint32, POINTER(c_uint32), POINTER(c_uint32)], c_int32),
"CGImageGetBitsPerPixel": ("core", [c_void_p], int),
"CGImageGetBytesPerRow": ("core", [c_void_p], int),
"CGImageGetBitsPerPixel": ("core", [c_void_p], c_size_t),
"CGImageGetBytesPerRow": ("core", [c_void_p], c_size_t),
"CGImageGetDataProvider": ("core", [c_void_p], c_void_p),
"CGImageGetHeight": ("core", [c_void_p], int),
"CGImageGetWidth": ("core", [c_void_p], int),
"CGImageGetHeight": ("core", [c_void_p], c_size_t),
"CGImageGetWidth": ("core", [c_void_p], c_size_t),
"CGRectStandardize": ("core", [CGRect], CGRect),
"CGRectUnion": ("core", [CGRect, CGRect], CGRect),
"CGWindowListCreateImage": ("core", [CGRect, c_uint32, c_uint32, c_uint32], c_void_p),
Expand Down Expand Up @@ -197,7 +207,7 @@ def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:

width = core.CGImageGetWidth(image_ref)
height = core.CGImageGetHeight(image_ref)
prov = copy_data = None
copy_data = None
try:
prov = core.CGImageGetDataProvider(image_ref)
copy_data = core.CGDataProviderCopyData(prov)
Expand All @@ -219,10 +229,9 @@ def _grab_impl(self, monitor: Monitor, /) -> ScreenShot:
cropped.extend(data[start:end])
data = cropped
finally:
if prov:
core.CGDataProviderRelease(prov)
Comment thread
BoboTiG marked this conversation as resolved.
if copy_data:
core.CFRelease(copy_data)
core.CFRelease(image_ref)

return self.cls_image(data, monitor, size=Size(width, height))

Expand Down