Skip to content

Fix static analysis findings in GC bridge and NativeAOT runtime#127893

Open
Copilot wants to merge 10 commits intomainfrom
copilot/fix-static-analysis-issues
Open

Fix static analysis findings in GC bridge and NativeAOT runtime#127893
Copilot wants to merge 10 commits intomainfrom
copilot/fix-static-analysis-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 6, 2026

Note

This PR description was generated with AI assistance.

Summary

  • Fixed allocator mismatch in src/coreclr/gc/gcbridge.cpp by replacing free with delete[] for memory allocated via new[].
  • Fixed potential null-dereference path in NativeAOT stress log by replacing heap-allocated CrstStatic with inline minipal_mutex, and asserting that minipal_mutex_init succeeds.
  • Fixed invalid handle cleanup in src/coreclr/nativeaot/Runtime/windows/PalMinWin.cpp by guarding CloseHandle calls for hMap and hFile.
  • Replaced CRITSEC_COOKIE lock with minipal_mutex lock in src/coreclr/inc/stresslog.h (mirroring the same change already made in the NativeAOT stress log header), and updated src/coreclr/utilcode/stresslog.cpp to use minipal_mutex_init, minipal_mutex_enter, and minipal_mutex_leave accordingly.

Validation

  • Baseline build before edits: ./build.sh clr+libs+host (pass)
  • Post-change build: ./build.sh clr+libs+host (pass)
  • Parallel validation:
    • Code Review: pass (no remaining comments)
    • CodeQL: no alerts (analysis skipped due to DB size limit)

Notes

  • Incorporated PR feedback to use bool success; success = minipal_mutex_init(&theLog.lock); _ASSERTE(success); instead of returning on initialization failure.
  • The StressLogLockHolder typedef in stresslog.h was updated from Holder<CRITSEC_COOKIE, ...> to Holder<minipal_mutex*, ...>, and call sites updated to pass &theLog.lock.
  • No focused runtime test suite was run for these specific low-level internal changes in this environment; full component build succeeded before and after changes.

Copilot AI and others added 2 commits May 6, 2026 23:49
Comment thread src/coreclr/nativeaot/Runtime/stressLog.cpp Outdated
@jkotas jkotas marked this pull request as ready for review May 7, 2026 00:01
@jkotas jkotas requested a review from MichalStrehovsky as a code owner May 7, 2026 00:01
Copilot AI review requested due to automatic review settings May 7, 2026 00:01
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@jkotas jkotas requested a review from BrzVlad May 7, 2026 00:03
@jkotas jkotas closed this May 7, 2026
@jkotas jkotas reopened this May 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI requested a review from jkotas May 7, 2026 00:23
Copilot finished work on behalf of jkotas May 7, 2026 00:23
Comment thread src/coreclr/nativeaot/Runtime/stressLog.cpp Outdated
Copilot AI review requested due to automatic review settings May 7, 2026 00:29
Comment thread src/coreclr/nativeaot/Runtime/inc/stressLog.h
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/nativeaot/Runtime/stressLog.cpp Outdated
Comment thread src/coreclr/nativeaot/Runtime/stressLog.cpp Outdated
Copilot AI review requested due to automatic review settings May 7, 2026 00:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/nativeaot/Runtime/inc/stressLog.h
Comment on lines +98 to +100
bool success;
success = minipal_mutex_init(&theLog.lock);
_ASSERTE(success);
Copilot AI and others added 2 commits May 7, 2026 00:51
…g.h and update stresslog.cpp

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/26128bb6-29c4-4931-9bcb-12d921bc1f7a

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
…OT stressLog.cpp

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/26128bb6-29c4-4931-9bcb-12d921bc1f7a

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 7, 2026 00:54
Copilot finished work on behalf of jkotas May 7, 2026 00:55
Copilot AI requested a review from jkotas May 7, 2026 00:55
#endif

typedef Holder<CRITSEC_COOKIE, StressLog::Enter, StressLog::Leave, 0, CompareDefault<CRITSEC_COOKIE>> StressLogLockHolder;
typedef Holder<minipal_mutex*, StressLog::Enter, StressLog::Leave, 0, CompareDefault<minipal_mutex*>> StressLogLockHolder;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot Delete this and replace it with minipal::MutexHolder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 346077a7. Deleted the StressLogLockHolder typedef and the Enter/Leave static methods. Updated Terminate and CreateThreadStressLog in stresslog.cpp to use minipal::MutexHolder directly.

Copilot AI requested review from Copilot and removed request for Copilot May 7, 2026 01:33
Copilot AI requested review from Copilot and removed request for Copilot May 7, 2026 01:35
Copilot finished work on behalf of jkotas May 7, 2026 01:36
Copilot AI requested a review from jkotas May 7, 2026 01:36
@jkotas
Copy link
Copy Markdown
Member

jkotas commented May 7, 2026

@copilot Revert last two commits. They do not look like an improvement

Copilot AI requested review from Copilot and removed request for Copilot May 7, 2026 01:56
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 7, 2026

@copilot Revert last two commits. They do not look like an improvement

Done in commit cf6e7797. Both src/coreclr/inc/stresslog.h and src/coreclr/utilcode/stresslog.cpp have been reverted to their state before those two commits.

Copilot finished work on behalf of jkotas May 7, 2026 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants