Skip to content

Commit 720446b

Browse files
authored
MAC OSX: AXUIElement Bad Access Ref (#45)
* fix more leaks * fix comment
1 parent 46bf7db commit 720446b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/macos.mm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ bool _requestAccessibility(bool showDialog) {
3030
NSNumber *windowNumber = info[(id)kCGWindowNumber];
3131

3232
if ([windowNumber intValue] == handle) {
33-
NSDictionary* windowInfo = (NSDictionary*)CFPropertyListCreateDeepCopy(kCFAllocatorDefault, (CFPropertyListRef)info, kCFPropertyListMutableContainers);
33+
// Retain property list so it doesn't get release w. windowList
34+
CFRetain((CFPropertyListRef)info);
3435
CFRelease(windowList);
35-
return windowInfo;
36+
return info;
3637
}
3738
}
3839

@@ -47,12 +48,14 @@ AXUIElementRef getAXWindow(int pid, int handle) {
4748
AXUIElementCopyAttributeValues(app, kAXWindowsAttribute, 0, 100, &windows);
4849

4950
for (id child in (NSArray *)windows) {
50-
auto window = (AXUIElementRef) child;
51+
AXUIElementRef window = (AXUIElementRef) child;
5152

5253
CGWindowID windowId;
5354
_AXUIElementGetWindow(window, &windowId);
5455

5556
if (windowId == handle) {
57+
// Retain returned window so it doesn't get released with rest of list
58+
CFRetain(window);
5659
CFRelease(windows);
5760
return window;
5861
}
@@ -74,7 +77,8 @@ void cacheWindowByInfo(NSDictionary* info) {
7477
if (info) {
7578
NSNumber *ownerPid = info[(id)kCGWindowOwnerPID];
7679
NSNumber *windowNumber = info[(id)kCGWindowNumber];
77-
80+
// Release dictionary info property since we're done with it
81+
CFRelease((CFPropertyListRef)info);
7882
cacheWindow([windowNumber intValue], [ownerPid intValue]);
7983
}
8084
}

0 commit comments

Comments
 (0)