Severity: Warning
File: setup/taskschd/ServyFailureEmail.ps1
Lines: 183-188
} finally {
if (\$null -ne \$mailMessage) { \$mailMessage.Dispose() }
# .NET 3.5 SmtpClient doesn't implement IDisposable (PS 2.0 limitation)
# but we null it for GC safety.
\$smtp = \$null
}
The script declares #Requires -Version 3.0 (line 1), so the PowerShell 2.0 / .NET 3.5 reasoning in the inline comment does not apply. PowerShell 3.0+ runs on .NET 4.0+, where System.Net.Mail.SmtpClient implements IDisposable (added in .NET 4.0). The comment justifies skipping Dispose() based on a constraint that does not match this script's documented prerequisites.
SmtpClient holds an underlying TCP connection (and, with EnableSsl = \$true, an SSL stream). Without Dispose() the connection is closed only when finalization runs — under a Scheduled Task that runs every few minutes this can briefly leak SMTP sockets and SSL handles to the GC.
Same bug appears in setup/taskschd/ServyFailureNotification.ps1 if it constructs SmtpClient; please verify.
Suggested fix: Dispose the SmtpClient explicitly:
} finally {
if (\$null -ne \$mailMessage) { \$mailMessage.Dispose() }
if (\$null -ne \$smtp) { \$smtp.Dispose() }
}
And update the misleading comment, or remove it entirely.
Severity: Warning
File:
setup/taskschd/ServyFailureEmail.ps1Lines: 183-188
The script declares
#Requires -Version 3.0(line 1), so the PowerShell 2.0 / .NET 3.5 reasoning in the inline comment does not apply. PowerShell 3.0+ runs on .NET 4.0+, whereSystem.Net.Mail.SmtpClientimplementsIDisposable(added in .NET 4.0). The comment justifies skippingDispose()based on a constraint that does not match this script's documented prerequisites.SmtpClientholds an underlying TCP connection (and, withEnableSsl = \$true, an SSL stream). WithoutDispose()the connection is closed only when finalization runs — under a Scheduled Task that runs every few minutes this can briefly leak SMTP sockets and SSL handles to the GC.Same bug appears in
setup/taskschd/ServyFailureNotification.ps1if it constructsSmtpClient; please verify.Suggested fix: Dispose the
SmtpClientexplicitly:And update the misleading comment, or remove it entirely.