Skip to content

Commit

Permalink
Fixes memory leak in EventLog fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Nov 15, 2023
1 parent 36e8198 commit e5ee6c2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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

0 comments on commit e5ee6c2

Please sign in to comment.