Skip to content

SR-3002: DispatchData.enumerateBytes on Linux leaks the block #186

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

Merged
merged 1 commit into from
Dec 8, 2016

Conversation

dgrove-oss
Copy link
Contributor

To avoid leaking the block parameter of enumerateBytes,
we need to directly call CDispatch.dispatch_data_apply
(not _swift_dispatch_data_apply). However, we need to tell
the compiler that the internal closure that translates between
the C and Swift layers will not cause the captured block
parameter to escape. If SR-2313 were implemented, we could use
withoutActuallyEscaping. Since withoutActuallyEscaping is not available,
we instead use unsafeBitCast to bypass the compiler's analysis.

To avoid leaking the block parameter of enumerateBytes,
we need to directly call CDispatch.dispatch_data_apply
(not _swift_dispatch_data_apply). However, we need to tell
the compiler that the internal closure that translates between
the C and Swift layers will not cause the captured block
parameter to escape.  If SR-2313 were implemented, we could use
withoutActuallyEscaping.  Since withoutActuallyEscaping is not available,
we instead use unsafeBitCast to bypass the compiler's analysis.
@dgrove-oss
Copy link
Contributor Author

@MadCoder any comments on this one? If the patch looks ok I will go ahead and create a PR to the Swift3 branch as well.

@MadCoder
Copy link
Contributor

sorry for some reason it fell through the cracks.

it looks reasonnable to me @mwwa what's your take? do we need the same in the compiler's overlay?

@dgrove-oss
Copy link
Contributor Author

I believe it is a Linux-only problem; initial bug report reported it leaked on Linux but not on Darwin.

@dgrove-oss
Copy link
Contributor Author

I created the matching Swift3 PR: #189. If we do get a Swift 3.0.2 release it would be nice to get this fix into it.

@dgrove-oss
Copy link
Contributor Author

@MadCoder @mwwa ok to merge this to master? it went into swift3 branch a while ago.

@MadCoder MadCoder merged commit a055ddb into swiftlang:master Dec 8, 2016
@dgrove-oss dgrove-oss deleted the SR-3002 branch December 8, 2016 16:00
das pushed a commit that referenced this pull request Feb 21, 2017
SR-3002: DispatchData.enumerateBytes on Linux leaks the block

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
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.

4 participants