From be207f0224d16bd9f8db47b07292473728927e22 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 15 Nov 2023 13:29:01 +0100 Subject: [PATCH] Fixes EventLog provider memory leak --- doc/31-Changelog.md | 8 ++++++-- provider/eventlog/Get-IcingaEventLog.psm1 | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index f8d35b6f..437f1da9 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -9,9 +9,13 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic # 1.12.0 (tbd) -### Enhancements +# 1.11.2 (tbd) + +### Bugfixes + +* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information -# 1.11.1 (tbd) +# 1.11.1 (2023-11-07) ### Bugfixes diff --git a/provider/eventlog/Get-IcingaEventLog.psm1 b/provider/eventlog/Get-IcingaEventLog.psm1 index f6199032..e8257081 100644 --- a/provider/eventlog/Get-IcingaEventLog.psm1 +++ b/provider/eventlog/Get-IcingaEventLog.psm1 @@ -61,6 +61,8 @@ function Get-IcingaEventLog() [hashtable]$UserFilter = @{ }; [hashtable]$SeverityFilter = @{ }; + [array]$FilteredEvents = @(); + [bool]$MemoryCleared = $FALSE; if ($null -ne $IncludeUsername -And $IncludeUsername.Count -ne 0) { foreach ($entry in $IncludeUsername) { @@ -137,7 +139,6 @@ function Get-IcingaEventLog() } if ($UserFilter.Count -ne 0 -Or $SeverityFilter.Count -ne 0 -Or $null -ne $IncludeEventId -Or $null -ne $ExcludeEventId -Or $null -ne $ExcludeUsername -Or $null -ne $ExcludeEntryType -Or $null -ne $ExcludeMessage -Or $null -ne $IncludeMessage -Or $null -ne $IncludeSource -Or $null -ne $ExcludeSource) { - $filteredEvents = @(); foreach ($event in $events) { if ($event.TimeCreated -lt $EventsAfter) { @@ -231,10 +232,16 @@ function Get-IcingaEventLog() continue; } - $filteredEvents += $event; + $FilteredEvents += $event; } - $events = $filteredEvents; + if ($null -ne $events) { + $events.Dispose(); + $events = $null; + $MemoryCleared = $TRUE; + } + + $events = $FilteredEvents; } $groupedEvents = @{ @@ -279,5 +286,11 @@ function Get-IcingaEventLog() } } + if ($MemoryCleared -eq $FALSE) { + $events.Dispose(); + } + + $events = $null; + return $groupedEvents; }