Fixes memory leak in EventLog fetcher

This commit is contained in:
Lord Hepipud 2023-11-15 14:31:40 +01:00
parent 36e81985b2
commit f59f146bee
4 changed files with 35 additions and 0 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}