Skip to content

Commit

Permalink
Fix memory leak - only track vpin once
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Apr 20, 2024
1 parent 0029762 commit fe24671
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion IO_EXIOExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,20 @@ class EXIOExpander : public IODevice {
}
}

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 {
Expand All @@ -259,7 +272,7 @@ class EXIOExpander : public IODevice {
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);
Expand Down

0 comments on commit fe24671

Please sign in to comment.