icinga-powershell-framework/lib/core/tools/Add-IcingaHashtableItem.psm1
Lord Hepipud 9df17e1068 Fixes Service Check Background Daemon Memory leak
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
2019-11-22 19:42:48 +01:00

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;
}