From 00009be17055da996522c97ae07ff85564ed14e4 Mon Sep 17 00:00:00 2001 From: gstellenberg Date: Tue, 23 Feb 2010 13:20:21 -0600 Subject: [PATCH] Fixed linked rules free list maintenance bug. --- src/PRDevice.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index b764538..15a6fbf 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -544,10 +544,14 @@ PRResult PRDevice::SwitchUpdateRule(uint8_t switchNum, PREventType eventType, PR // Because we're redefining the rule chain, we need to remove all previously existing links and return the indexes to the free list. PRSwitchRuleInternal *oldRule = GetSwitchRuleByIndex(newRuleIndex); + + uint16_t oldLinkIndex; while (oldRule->linkActive) { + // Save old link index so it can freed after the linked rule is retrieved. + oldLinkIndex = oldRule->linkIndex; oldRule = GetSwitchRuleByIndex(oldRule->linkIndex); - freeSwitchRuleIndexes.push(oldRule->linkIndex); + freeSwitchRuleIndexes.push(oldLinkIndex); if (freeSwitchRuleIndexes.size() > 128) // Detect a corrupted link-related values before it eats up all of the memory. {