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

Use weak ref to fix crash when process exits after view is released #293

Merged
merged 1 commit into from
May 9, 2023

Conversation

kdrag0n
Copy link
Contributor

@kdrag0n kdrag0n commented May 7, 2023

If a LocalProcess is terminated or exits right before the hosting LocalProcessTerminalView is released, the processTerminated call crashes the app with the following error:

Fatal error: Attempted to read an unowned reference but the object was already deallocated

All usages of delegate already have nil checks, so just change the variable from unowned to weak to fix the issue. There's no point in calling the delegate when it no longer exists.

If a LocalProcess is terminated or exits right before the hosting
LocalProcessTerminalView is released, the processTerminated call crashes
the app with the following error:

Fatal error: Attempted to read an unowned reference but the object was already deallocated

All usages of delegate already have nil checks, so just change the
variable from unowned to weak to fix the issue. There's no point in
calling the delegate when it no longer exists.
@kdrag0n kdrag0n changed the title Use weak ref to fix crash on process exit after view released Use weak ref to fix crash when process exits after view is released May 7, 2023
@migueldeicaza
Copy link
Owner

Thank you for your patch!

@migueldeicaza
Copy link
Owner

Mhm, I wonder why changing unowned to weak fixes this?

@migueldeicaza migueldeicaza merged commit f652d6c into migueldeicaza:main May 9, 2023
@kdrag0n
Copy link
Contributor Author

kdrag0n commented May 9, 2023

I think it's because unowned is strict and crashes if you try to access a reference to a freed object. weak returns nil instead, which is more in line with the expected behavior for delegates.

@Lakr233
Copy link

Lakr233 commented May 10, 2023

unowned should be banned for 99% of cases, it is dangerous as we do not have, most of time, control to ARC overtime so the pointer should be set to nil when release (weak) instead of keep it (unowned)

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.

3 participants