Skip to content

Commit 00ebc50

Browse files
authored
Merge pull request #535 from waynepiekarski/master
Always clean up previous I2C object before new to avoid leaking memory
2 parents a4a950e + 84c71a5 commit 00ebc50

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libraries/Wire/Wire.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ arduino::MbedI2C::MbedI2C(int sda, int scl) : _sda(digitalPinToPinName(sda)), _s
2828
arduino::MbedI2C::MbedI2C(PinName sda, PinName scl) : _sda(sda), _scl(scl), usedTxBuffer(0), slave_th(osPriorityNormal, 2048, nullptr, "I2CSlave") {}
2929

3030
void arduino::MbedI2C::begin() {
31+
end();
3132
master = new mbed::I2C(_sda, _scl);
3233
}
3334

3435
void arduino::MbedI2C::begin(uint8_t slaveAddr) {
3536
#ifdef DEVICE_I2CSLAVE
37+
end();
3638
slave = new mbed::I2CSlave((PinName)_sda, (PinName)_scl);
3739
slave->address(slaveAddr << 1);
3840
slave_th.start(mbed::callback(this, &arduino::MbedI2C::receiveThd));

0 commit comments

Comments
 (0)