Skip to content

Foundation: FileHandle.swift: memory leak in _readDataOfLength #1155

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
Aug 11, 2017
Merged

Foundation: FileHandle.swift: memory leak in _readDataOfLength #1155

merged 1 commit into from
Aug 11, 2017

Conversation

mattrajca
Copy link
Contributor

dynamicBuffer will never be freed if total > 0. Fix this by giving the underlying Data a "free" destructor. This is covered by existing tests.

@ianpartridge
Copy link
Contributor

The line in question was added in 188a4e1 so tagging @phausler.

@@ -109,7 +109,7 @@ open class FileHandle : NSObject, NSSecureCoding {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, can we change this:

if (0 == total) { } if (total > 0) { } to an if-else?

Just so we make sure we can't exit this function without either a free or data creation with .free.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The earlier code paths ensure that the total will never be negative. Regardless, I updated this to cover all cases and added an assertion in the unreachable case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parkera Please review the updated commit.

`dynamicBuffer` will never be freed if `total > 0`. Fix this by
giving the underlying Data a "free" destructor. This is covered
by existing tests.
@ianpartridge
Copy link
Contributor

@swift-ci please test and merge

1 similar comment
@alblue
Copy link
Contributor

alblue commented Aug 8, 2017

@swift-ci please test and merge

@mattrajca
Copy link
Contributor Author

@ianpartridge @alblue Hmm, seems like there were some server errors: Server returned HTTP response code: 405, message: 'Method Not Allowed' for URL: https://api.github.com/repos/apple/swift-corelibs-foundation/pulls/1155/merge

@ianpartridge
Copy link
Contributor

@swift-ci please test and merge

1 similar comment
@ianpartridge
Copy link
Contributor

@swift-ci please test and merge

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.

5 participants