Skip to content

[5.9][Runtime] Fix memory leak in -[__SwiftNativeNSError description] for large error values. #66298

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

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented Jun 2, 2023

Cherry-pick #66277 to release/5.9.

Balance the call to allocateBufferIn with a call to deallocateBufferIn. When an error value is small, the missing deallocateBufferIn doesn't do anything. But when the error value is a larger struct that doesn't fit inline, we need deallocateBufferIn to avoid leaking the allocation.

rdar://109933822

… for large error values.

Balance the call to allocateBufferIn with a call to deallocateBufferIn. When an error value is small, the missing deallocateBufferIn doesn't do anything. But when the error value is a larger struct that doesn't fit inline, we need deallocateBufferIn to avoid leaking the allocation.

rdar://109933822
(cherry picked from commit 01300a6)
@mikeash mikeash requested a review from a team as a code owner June 2, 2023 13:53
@mikeash
Copy link
Contributor Author

mikeash commented Jun 2, 2023

• Description: This fixes a memory leak when calling the description method of an NSError containing an Error type that's a large struct.
• Risk: Low. This is a small change to free a buffer that was allocated just before.
• Original PR: #66277
• Reviewed By: @al45tair
• Testing: The existing test for this method was modified to also test a large struct.
• Resolves: rdar://109933822

@mikeash
Copy link
Contributor Author

mikeash commented Jun 2, 2023

@swift-ci please test

@mikeash mikeash merged commit 22bdcb2 into swiftlang:release/5.9 Jun 2, 2023
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