Skip to content

Commit 9713a1c

Browse files
authored
Merge pull request #375 from Icinga:fix/eventlog_provider_memory_leak
Fix: EventLog provider memory leak
2 parents fb9ee9c + 554773a commit 9713a1c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

doc/31-Changelog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
99

1010
# 1.12.0 (tbd)
1111

12-
### Enhancements
12+
# 1.11.2 (tbd)
13+
14+
### Bugfixes
15+
16+
* [#375](https://github.com/Icinga/icinga-powershell-plugins/pull/375) Fixes a memory leak on the Icinga EventLog provider for fetching Windows EventLog information
1317

14-
# 1.11.1 (tbd)
18+
# 1.11.1 (2023-11-07)
1519

1620
### Bugfixes
1721

provider/eventlog/Get-IcingaEventLog.psm1

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ function Get-IcingaEventLog()
6161

6262
[hashtable]$UserFilter = @{ };
6363
[hashtable]$SeverityFilter = @{ };
64+
[array]$FilteredEvents = @();
65+
[bool]$MemoryCleared = $FALSE;
6466

6567
if ($null -ne $IncludeUsername -And $IncludeUsername.Count -ne 0) {
6668
foreach ($entry in $IncludeUsername) {
@@ -137,7 +139,6 @@ function Get-IcingaEventLog()
137139
}
138140

139141
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) {
140-
$filteredEvents = @();
141142
foreach ($event in $events) {
142143

143144
if ($event.TimeCreated -lt $EventsAfter) {
@@ -231,10 +232,19 @@ function Get-IcingaEventLog()
231232
continue;
232233
}
233234

234-
$filteredEvents += $event;
235+
$FilteredEvents += $event;
235236
}
236237

237-
$events = $filteredEvents;
238+
if ($null -ne $events) {
239+
if ($null -ne ($events | Get-Member -Name 'Dispose')) {
240+
$events.Dispose();
241+
}
242+
243+
$events = $null;
244+
$MemoryCleared = $TRUE;
245+
}
246+
247+
$events = $FilteredEvents;
238248
}
239249

240250
$groupedEvents = @{
@@ -279,5 +289,14 @@ function Get-IcingaEventLog()
279289
}
280290
}
281291

292+
if ($MemoryCleared -eq $FALSE) {
293+
if ($null -ne ($events | Get-Member -Name 'Dispose')) {
294+
$events.Dispose();
295+
}
296+
}
297+
298+
$events = $null;
299+
$FilteredEvents = $null;
300+
282301
return $groupedEvents;
283302
}

0 commit comments

Comments
 (0)