Skip to content

Commit bd7f61a

Browse files
benmalenfantfpistm
authored andcommitted
Fix Wire memory leak
Signed-off-by: Benoit Malenfant <[email protected]>
1 parent 3a3ff84 commit bd7f61a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: libraries/Wire/src/Wire.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ TwoWire::TwoWire()
3838
memset((void *)&_i2c, 0, sizeof(_i2c));
3939
_i2c.sda = digitalPinToPinName(SDA);
4040
_i2c.scl = digitalPinToPinName(SCL);
41+
42+
txBuffer = nullptr;
43+
txBufferAllocated = 0;
44+
rxBuffer = nullptr;
45+
rxBufferAllocated = 0;
4146
}
4247

4348
TwoWire::TwoWire(uint32_t sda, uint32_t scl)
4449
{
4550
memset((void *)&_i2c, 0, sizeof(_i2c));
4651
_i2c.sda = digitalPinToPinName(sda);
4752
_i2c.scl = digitalPinToPinName(scl);
53+
54+
txBuffer = nullptr;
55+
txBufferAllocated = 0;
56+
rxBuffer = nullptr;
57+
rxBufferAllocated = 0;
4858
}
4959

5060
/**
@@ -74,14 +84,10 @@ void TwoWire::begin(uint8_t address, bool generalCall, bool NoStretchMode)
7484
{
7585
rxBufferIndex = 0;
7686
rxBufferLength = 0;
77-
rxBuffer = nullptr;
78-
rxBufferAllocated = 0;
7987
resetRxBuffer();
8088

8189
txDataSize = 0;
8290
txAddress = 0;
83-
txBuffer = nullptr;
84-
txBufferAllocated = 0;
8591
resetTxBuffer();
8692

8793
_i2c.__this = (void *)this;

0 commit comments

Comments
 (0)