1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 04:41:24 +01:00

Fix memory leak - only track vpin once

This commit is contained in:
peteGSX 2024-04-21 09:28:58 +10:00
parent 0029762fc6
commit fe24671ad2

View File

@ -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);