Skip to content

Commit

Permalink
Fixes EventLog provider memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Nov 15, 2023
1 parent 6669c1c commit 96a4212
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 17 additions & 3 deletions provider/eventlog/Get-IcingaEventLog.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = @{
Expand Down Expand Up @@ -279,5 +286,12 @@ function Get-IcingaEventLog()
}
}

if ($MemoryCleared -eq $FALSE) {
$events.Dispose();
}

$events = $null;
$FilteredEvents = $null;

return $groupedEvents;
}

0 comments on commit 96a4212

Please sign in to comment.