Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault on m1 #828

Merged
merged 1 commit into from
Aug 31, 2022
Merged
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
22 changes: 13 additions & 9 deletions src/apple/macos/component/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::ffi::CStr;

use core_foundation_sys::array::{CFArrayGetCount, CFArrayGetValueAtIndex};
use core_foundation_sys::base::kCFAllocatorDefault;
use core_foundation_sys::base::{kCFAllocatorDefault, CFRetain};
use core_foundation_sys::string::{
kCFStringEncodingUTF8, CFStringCreateWithBytes, CFStringGetCStringPtr,
};
Expand Down Expand Up @@ -43,11 +43,18 @@ impl Components {
None => return,
};

// FIXME: Do we really need to re-create a new `client` every time?
let client = match CFReleaser::new(IOHIDEventSystemClientCreate(kCFAllocatorDefault)) {
Some(c) => c,
None => return,
};
if self.client.is_none() {
let client =
match CFReleaser::new(IOHIDEventSystemClientCreate(kCFAllocatorDefault)) {
Some(c) => c,
None => return,
};
// Without this call, client is freed during the execution of the program. It must be kept!
CFRetain(client.inner() as _);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original issue was because of self.client.replace(client);. Did you test without this call to CFRetain? If not, can you quickly check it please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, at first I think it was because of self.client.replace(client) too, and I did the test, it's not.
and from this crash report
it seems it is the dispatch_worker trying to release the client

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How weird... Oh well, that answers my question at least. Can you add a comment above the call to CFRetain saying something like this:

// Without this call, client is freed during the execution of the program. It must be kept!

self.client = Some(client);
}

let client = self.client.as_ref().unwrap();

let _ = IOHIDEventSystemClientSetMatching(client.inner(), matches.inner());

Expand Down Expand Up @@ -95,9 +102,6 @@ impl Components {

self.inner.push(component);
}

// FIXME: Do we really need to re-create a new `client` every time?
self.client.replace(client);
}
}
}
Expand Down