fix(Elysium.Common): dispose DirectoryEntry/ADSI objects
Test-ReplicationPermissions and Test-DCClockSkew each build a DirectoryEntry (holding a live ADSI/COM binding, with a plaintext credential) and never call .Dispose(), leaking the underlying COM resource on every invocation - noticeable across a run that checks multiple domains/DCs in one session. Added finally blocks to dispose both. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -400,6 +400,7 @@ function Test-ReplicationPermissions {
|
|||||||
$rightsToCheck = $ncEntry.Value
|
$rightsToCheck = $ncEntry.Value
|
||||||
|
|
||||||
$acl = $null
|
$acl = $null
|
||||||
|
$de = $null
|
||||||
try {
|
try {
|
||||||
$de = New-Object System.DirectoryServices.DirectoryEntry(
|
$de = New-Object System.DirectoryServices.DirectoryEntry(
|
||||||
"LDAP://$Server/$ncDN",
|
"LDAP://$Server/$ncDN",
|
||||||
@@ -411,6 +412,8 @@ function Test-ReplicationPermissions {
|
|||||||
} catch {
|
} catch {
|
||||||
Write-Warning ("Could not read ACL on '$ncDN' for replication permission pre-check: {0}. Skipping." -f $_.Exception.Message)
|
Write-Warning ("Could not read ACL on '$ncDN' for replication permission pre-check: {0}. Skipping." -f $_.Exception.Message)
|
||||||
continue
|
continue
|
||||||
|
} finally {
|
||||||
|
if ($de) { $de.Dispose() }
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($rightName in $rightsToCheck.Keys) {
|
foreach ($rightName in $rightsToCheck.Keys) {
|
||||||
@@ -481,6 +484,7 @@ function Test-DCClockSkew {
|
|||||||
[Parameter(Mandatory)][string]$Server,
|
[Parameter(Mandatory)][string]$Server,
|
||||||
[Parameter(Mandatory)][System.Management.Automation.PSCredential]$Credential
|
[Parameter(Mandatory)][System.Management.Automation.PSCredential]$Credential
|
||||||
)
|
)
|
||||||
|
$rootDse = $null
|
||||||
try {
|
try {
|
||||||
$rootDse = New-Object System.DirectoryServices.DirectoryEntry(
|
$rootDse = New-Object System.DirectoryServices.DirectoryEntry(
|
||||||
"LDAP://$Server/RootDSE",
|
"LDAP://$Server/RootDSE",
|
||||||
@@ -502,5 +506,7 @@ function Test-DCClockSkew {
|
|||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
Write-Warning ("Could not check clock skew against '{0}': {1}" -f $Server, $_.Exception.Message)
|
Write-Warning ("Could not check clock skew against '{0}': {1}" -f $Server, $_.Exception.Message)
|
||||||
|
} finally {
|
||||||
|
if ($rootDse) { $rootDse.Dispose() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user