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

clean up the callback in exit_grab() for macos #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xosxos
Copy link

@xosxos xosxos commented Nov 25, 2024

Otherwise the variables moved into it will never be dropped, and for example, channels inside the callback will not receive.

@xosxos xosxos changed the title clean up the callback on exit_grab() for macos clean up the callback in exit_grab() for macos Nov 25, 2024
@rustdesk
Copy link
Collaborator

rustdesk commented Nov 25, 2024

Does this fix any bug in RustDesk?

@xosxos
Copy link
Author

xosxos commented Nov 25, 2024

Well, I ran into the following issue:

let (tx, rx) = channel();
let tx = Arc::new(tx);

let callback = move |event: Event| -> Option<Event> {
    if something {
          tx.send(send_an_item);
          exit_grab();
    }
};

// Blocking
let _ = grab(callback);

drop(tx);

// Cannot receive items, because a reference to `tx` exists inside the boxed callback function
let receive_items = rx.iter().collect();

I suppose the question is: should the callback function live on the heap for the duration of the entire program regardless of grab_exit. As far as I could see, the callback cannot be called after the exit, and thus, it should not live. But I might be wrong as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants