Skip to content

Commit

Permalink
Fix Wire memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Malenfant <25072667+benmalenfant@users.noreply.github.com>
  • Loading branch information
benmalenfant authored and fpistm committed Jul 16, 2024
1 parent 3a3ff84 commit bd7f61a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,23 @@ TwoWire::TwoWire()
memset((void *)&_i2c, 0, sizeof(_i2c));
_i2c.sda = digitalPinToPinName(SDA);
_i2c.scl = digitalPinToPinName(SCL);

txBuffer = nullptr;
txBufferAllocated = 0;
rxBuffer = nullptr;
rxBufferAllocated = 0;
}

TwoWire::TwoWire(uint32_t sda, uint32_t scl)
{
memset((void *)&_i2c, 0, sizeof(_i2c));
_i2c.sda = digitalPinToPinName(sda);
_i2c.scl = digitalPinToPinName(scl);

txBuffer = nullptr;
txBufferAllocated = 0;
rxBuffer = nullptr;
rxBufferAllocated = 0;
}

/**
Expand Down Expand Up @@ -74,14 +84,10 @@ void TwoWire::begin(uint8_t address, bool generalCall, bool NoStretchMode)
{
rxBufferIndex = 0;
rxBufferLength = 0;
rxBuffer = nullptr;
rxBufferAllocated = 0;
resetRxBuffer();

txDataSize = 0;
txAddress = 0;
txBuffer = nullptr;
txBufferAllocated = 0;
resetTxBuffer();

_i2c.__this = (void *)this;
Expand Down

0 comments on commit bd7f61a

Please sign in to comment.