diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 7112497a..c5165dd5 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -11,6 +11,14 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic [Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/28) +## 1.11.2 (tbd) + +[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/30) + +### Bugfixes + +* [#673](https://github.com/Icinga/icinga-powershell-framework/pull/673) Fixes a memory leak while fetching Windows EventLog information by using CLI tools and inside the Hyper-V provide + ## 1.11.1 (2023-11-07) [Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/29) diff --git a/lib/core/framework/Read-IcingaWindowsEventLog.psm1 b/lib/core/framework/Read-IcingaWindowsEventLog.psm1 index 03a26fe4..84ac66a1 100644 --- a/lib/core/framework/Read-IcingaWindowsEventLog.psm1 +++ b/lib/core/framework/Read-IcingaWindowsEventLog.psm1 @@ -52,6 +52,11 @@ function Read-IcingaWindowsEventLog() $CollectedEvents += $event; } + if ($null -ne $IcingaEvents) { + $IcingaEvents.Dispose(); + $IcingaEvents = $null; + } + $CollectedEvents = $CollectedEvents | Sort-Object { $_.TimeCreated }; foreach ($event in $CollectedEvents) { @@ -71,6 +76,8 @@ function Read-IcingaWindowsEventLog() Write-IcingaConsolePlain -Message '[{0}] {1}' -Objects $event.TimeCreated, $event.Message -ForeColor $ForeColor; } + $CollectedEvents = $null; + Start-Sleep -Seconds 1; # Force Icinga for Windows Garbage Collection Optimize-IcingaForWindowsMemory -ClearErrorStack; diff --git a/lib/core/tools/Show-IcingaEventLogAnalysis.psm1 b/lib/core/tools/Show-IcingaEventLogAnalysis.psm1 index 5c7c12b1..5302102a 100644 --- a/lib/core/tools/Show-IcingaEventLogAnalysis.psm1 +++ b/lib/core/tools/Show-IcingaEventLogAnalysis.psm1 @@ -11,6 +11,11 @@ function Show-IcingaEventLogAnalysis() try { [array]$BasicLogArray = Get-WinEvent -ListLog $LogName -ErrorAction Stop; $BasicLogData = $BasicLogArray[0]; + + if ($null -ne $BasicLogArray) { + $BasicLogArray.Dispose(); + $BasicLogArray = $null; + } } catch { Write-IcingaConsoleError 'Failed to fetch data for EventLog "{0}". Probably this log does not exist.' -Objects $LogName; return; @@ -81,6 +86,11 @@ function Show-IcingaEventLogAnalysis() $LogAnalysis.Minute.Average = [math]::Ceiling($LogAnalysis.Minute.Count / $LogAnalysis.Minute.Entries.Count); } + if ($null -ne $LogData) { + $LogData.Dispose(); + $LogData = $null; + } + foreach ($value in $LogAnalysis.Day.Entries.Values) { $LogAnalysis.Day.Maximum = Get-IcingaValue -Value $value -Compare $LogAnalysis.Day.Maximum -Maximum; } diff --git a/lib/provider/assets/hyperv/Get-IcingaProviderDataValuesHyperV.psm1 b/lib/provider/assets/hyperv/Get-IcingaProviderDataValuesHyperV.psm1 index 4949b70f..3149ae3f 100644 --- a/lib/provider/assets/hyperv/Get-IcingaProviderDataValuesHyperV.psm1 +++ b/lib/provider/assets/hyperv/Get-IcingaProviderDataValuesHyperV.psm1 @@ -102,6 +102,16 @@ function Get-IcingaProviderDataValuesHyperV() } } } + + if ($null -ne $InformationBlackoutTimes) { + $InformationBlackoutTimes.Dispose(); + $InformationBlackoutTimes = $null; + } + + if ($null -ne $WarningBlackoutTimes) { + $WarningBlackoutTimes.Dispose(); + $WarningBlackoutTimes = $null; + } } catch { Exit-IcingaThrowException -ExceptionType 'Custom' -CustomMessage 'Hyper-V Error' -ExceptionThrown $_.Exception.Message -Force; }