Skip to content

libSyntax: ensure copy constructor of OwnedString to release previously allocated data. rdar://35116413 #12610

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 4 commits into from
Oct 25, 2017
Merged

Conversation

nkcsgexi
Copy link
Contributor

Issue detected by the awesome leak sanitizer bot.

cc @gottesmm

…ly allocated data. rdar://35116413

Issue detected by the awesome leak sanitizer bot.
@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@@ -44,10 +44,15 @@ class OwnedString {
size_t Length;
StringOwnership Ownership;

void release() {
if (Ownership == StringOwnership::Copied)
free(const_cast<char *>(Data));
Copy link
Contributor

Choose a reason for hiding this comment

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

Quick drive by: Why are we freeing this. Why are we not using delete []?

On another note, I am just happy we are catching these leaks.

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3455cf7

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3455cf7


OwnedString(const OwnedString &Other) {
// Release previously allocated data.
release();
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't happen. Are you sure it didn't mean the copy assignment operator?

(Also, you should probably add move operators as well. Rule of Five!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you’re right. This meant to be the copy assignment operator. Will fix

@nkcsgexi
Copy link
Contributor Author

@jrose-apple could you please take another look?

@nkcsgexi
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi merged commit e861d51 into swiftlang:master Oct 25, 2017
@nkcsgexi nkcsgexi deleted the release-owned-string branch October 25, 2017 17:00
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