-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[SR-6942] publishing a reference to self in deinit causes Swift to be memory unsafe #49490
Comments
I thought we had one. @gparker42, @mikeash? |
Looks like we don't. |
IIRC we can't do that in the runtime because the compiler is omitting releases inside deinit for performance reasons. |
Could we get the compiler to emit an assert that the count at the end of deinit is whatever it thinks it’s supposed to be? |
shajrawi (JIRA User), do you know if this optimization is actually important? Catching escapes seems like it would be really useful. |
I'm all for performance but this one defeats memory safety which is AFAIK something Swift claims to have (unless you use stuff with |
@swift-ci create |
@gparker42 We aren't doing that anymore I don't think b/c you put in an assert into the runtime. |
Attachment: Download
Additional Detail from JIRA
md5: 5af5d21f748a661d7e9705da05799bbb
Issue Description:
There are many different programs that show this behaviour but for example, let's use
this program assigns the dying
self
reference to a global indeinit
(obviously a very bad idea). After the object has been de-initialised, we then call a method on the global which causes the program to crash in random ways... For example:the output of the program might be:
Shouldn't there be some assertion that at the very end of
deinit
the reference count is still 0?Rewriting the program slightly to
I get actually pretty bad behaviour, running this in a loop it prints:
so sometimes it crashes, sometimes it prints 12, sometimes 3, sometimes 2...
but same for
swift-4.1-DEVELOPMENT-SNAPSHOT-2018-01-10
The text was updated successfully, but these errors were encountered: