Don't attempt to unload cdac - #132028
Merged
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR clarifies that the cDAC (a NativeAOT library) should not be unloaded on Unix by guarding FreeLibrary calls with #ifndef HOST_UNIX, aligning intent with the prior change to prevent actual unmapping.
Changes:
- Skip unloading the cDAC library on Unix when initialization fails.
- Skip unloading the cDAC library on Unix during
CDACdestruction.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/debug/daccess/cdac.cpp | Adds HOST_UNIX guards around FreeLibrary calls to avoid attempting to unload cDAC on Unix. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/coreclr/debug/daccess/cdac.cpp:172
- On Unix the module is now intentionally kept loaded by skipping
FreeLibrary. Without an explanatory comment, this looks like a resource leak and makes the lifetime rule easy to misunderstand. Consider adding a short#elsecomment clarifying why unloading is avoided here.
#ifndef HOST_UNIX
::FreeLibrary(m_module);
#endif // HOST_UNIX
src/coreclr/debug/daccess/cdac.cpp:141
- On Unix this now intentionally skips freeing the cDAC module, which can look like an accidental leak/refcount imbalance to future maintainers. Add an explicit comment in the
#elsebranch explaining that this is deliberate (NativeAOT library unload is unsafe) so the behavior isn’t “fixed” later.
This issue also appears on line 170 of the same file.
#ifndef HOST_UNIX
::FreeLibrary(cdacLib);
#endif // HOST_UNIX
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
hoyosjs
reviewed
Aug 8, 2026
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/coreclr/debug/daccess/cdac.cpp:140
- Since
FreeLibrarywas removed, a failedcdac_reader_init(or any subsequentCDAC::Createcall) leaves the newly loaded module referenced forever. If DAC instances are created repeatedly in a long-lived process, this can accumulate module references unnecessarily. Consider caching the loadedHMODULEand reusing it for subsequentCreatecalls so the library is loaded once per process while still never being unloaded.
intptr_t handle;
if (init(descriptorAddr, &ReadFromTargetCallback, &WriteToTargetCallback, &ReadThreadContext, &WriteThreadContext, allocCallback, target, &handle) != 0)
{
return {};
}
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
This was referenced Aug 8, 2026
Open
jkotas
approved these changes
Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As cDAC is a NativeAOT library, it cannot be safely unloaded. #131960 should prevent an actual unmapping from happening, but this makes the intent clear.