Skip to content

[libSyntax] Resolve a memory leak leaking the syntax tree #18698

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 2 commits into from
Aug 14, 2018

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Aug 14, 2018

This resolves a memory leak that occurred if RawSyntax nodes are allocated without an arena using operator new. A ParserUnit would never release its ASTContext which in turn retains the SourceFile and thus the syntax tree. Deleting the ASTContext resolves this leak.

We need to then retain RawSyntax nodes from RawSyntaxCacheNode so they are not freed while still being referenced.

Previously RawSyntaxCacheNode was not increasing the RawSyntax refCount
and accessing a cached node would fail if the node had been deleted in
the meantime. We weren't hitting this so far, because all nodes were
allocated using a bump allocator and thus the underlying memory never
freed.
This resolves a memory leak.
@ahoppen ahoppen requested review from rintaro and nkcsgexi August 14, 2018 14:51
@ahoppen
Copy link
Member Author

ahoppen commented Aug 14, 2018

@swift-ci Please smoke test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Good catch!

@ahoppen ahoppen merged commit 093f917 into swiftlang:master Aug 14, 2018
@aschwaighofer
Copy link
Contributor

@ahoppen
Copy link
Member Author

ahoppen commented Aug 15, 2018

I'm investigating what the issue is.

@ahoppen
Copy link
Member Author

ahoppen commented Aug 15, 2018

I'm reverting the code that caused this issue for now in #18726.

ahoppen added a commit that referenced this pull request Aug 15, 2018
[libSyntax] Partly revert #18698 to fix ASAN bot
ahoppen added a commit to ahoppen/swift that referenced this pull request Aug 17, 2018
@ahoppen ahoppen deleted the leak-fix branch August 22, 2018 15:48
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.

3 participants