mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Fixes #20 This fixes the memory leak on the Service Check Background Daemon, mainly caused by not properly catching the boolean return values of `Add-IcingaHashtableItem`. The boolean values stayed within the scope, poluting the memory and causing functions to behave not as expected
25 lines
485 B
PowerShell
25 lines
485 B
PowerShell
function Add-IcingaHashtableItem()
|
|
{
|
|
param(
|
|
$Hashtable,
|
|
$Key,
|
|
$Value,
|
|
[switch]$Override
|
|
);
|
|
|
|
if ($null -eq $Hashtable) {
|
|
return $FALSE;
|
|
}
|
|
|
|
if ($Hashtable.ContainsKey($Key) -eq $FALSE) {
|
|
$Hashtable.Add($Key, $Value);
|
|
return $TRUE;
|
|
} else {
|
|
if ($Override) {
|
|
$Hashtable.Remove($Key);
|
|
$Hashtable.Add($Key, $Value);
|
|
return $TRUE;
|
|
}
|
|
}
|
|
return $FALSE;
|
|
}
|