Skip to content

[System.DirectoryServices] Fixed possible resource leak#120899

Merged
tarekgh merged 5 commits intodotnet:mainfrom
sancheolz:patch-1
Feb 16, 2026
Merged

[System.DirectoryServices] Fixed possible resource leak#120899
tarekgh merged 5 commits intodotnet:mainfrom
sancheolz:patch-1

Conversation

@sancheolz
Copy link
Contributor

It is worth explicitly calling Dispose for the policyHandle object, since it implements the IDisposable interface.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

It is worth explicitly calling Dispose for the policyHandle object, since it implements the IDisposable interface.
Copy link
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

This pull request addresses resource leaks in the System.DirectoryServices library by ensuring that SafeLsaPolicyHandle objects are properly disposed. SafeLsaPolicyHandle is a SafeHandle type that wraps an LSA policy handle and must be explicitly disposed to release native resources. The PR was identified by the Linux Verification Center using SVACE static analysis.

Changes:

  • Converted simple SafeLsaPolicyHandle usage to using var pattern in 7 methods for automatic disposal
  • Added explicit Dispose call in GetTrustedDomainInfo method where handle reassignment occurs

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

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

Looks good to me. @tarekgh; good with you as well?

@tarekgh tarekgh added this to the 11.0.0 milestone Feb 16, 2026
@tarekgh
Copy link
Member

tarekgh commented Feb 16, 2026

/ba-g the failure is Android specific and not related to the change.

@tarekgh tarekgh merged commit 1921fed into dotnet:main Feb 16, 2026
87 of 90 checks passed
@tarekgh
Copy link
Member

tarekgh commented Feb 16, 2026

Thanks @sancheolz for your help with the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.DirectoryServices community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants