Skip to content

[Runtime] Properly deallocate extended storage for conformance cache entries #80865

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

Conversation

DougGregor
Copy link
Member

When a conformance cache entry requires extended storage (i.e., for global actor isolation), we were using C++ new to allocate that storage and never freeing it. When the conformance cache gets cleared (e.g, due to loading a shared library containing conformances), these allocations would be leaked.

Switch over to malloc for these allocations so we don't get tangled with any user-provided C++ new implementations. Keep track of the allocations in a list, and when the conformance cache is cleared, move them over to the freelist for deallocation, eliminating a memory leak.

… free list

This memory is part of the conformance cache concurrent hash map, so
when we clear the conformance cache, record each of the allocated
pointers within the concurrent map's free list. This way, it'll be
freed with the rest of the concurrent map when it's safe to do so.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@al45tair FYI!

@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test Linux

@DougGregor DougGregor merged commit 0ec146a into swiftlang:main Apr 17, 2025
3 checks passed
@DougGregor DougGregor deleted the conformance-cache-extended-entry-deleak branch April 17, 2025 15:53
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