Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Memory leak in EventLog fetcher #673

Merged
merged 1 commit into from Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/100-General/10-Changelog.md
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions lib/core/framework/Read-IcingaWindowsEventLog.psm1
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions lib/core/tools/Show-IcingaEventLogAnalysis.psm1
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/provider/assets/hyperv/Get-IcingaProviderDataValuesHyperV.psm1
Expand Up @@ -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;
}
Expand Down