From fe24671ad25202416c1a6b88e1ec4c8e1efd198c Mon Sep 17 00:00:00 2001 From: peteGSX Date: Sun, 21 Apr 2024 09:28:58 +1000 Subject: [PATCH] Fix memory leak - only track vpin once --- IO_EXIOExpander.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/IO_EXIOExpander.h b/IO_EXIOExpander.h index c552dcb..a53af58 100644 --- a/IO_EXIOExpander.h +++ b/IO_EXIOExpander.h @@ -233,7 +233,20 @@ private: } } + bool isConfigured(VPIN vpin) const { + ConfiguredInput *current = _firstInput; + while (current != nullptr) { + if (current->getVpin() == vpin) { + return true; + } + current = current->getNext(); + } + return false; + } + void addConfiguredInput(ConfiguredInput *input) { + VPIN vpin = input->getVpin(); + if (isConfigured(vpin)) return; // Already have this captured, don't create it again if (!_firstInput) { _firstInput = input; } else { @@ -259,7 +272,7 @@ private: outBuffer, sizeof(outBuffer)); if (status == I2C_STATUS_OK) { if (responseBuffer[0] == EXIORDY) { - addConfiguredInput (new ConfiguredInput(vpin, configType, pullup)); + addConfiguredInput(new ConfiguredInput(vpin, configType, pullup)); return true; } else { DIAG(F("EXIOVpin %u cannot be used as a digital input pin"), (int)vpin);