Skip to content

Commit bd7f61a

Browse files
benmalenfantfpistm
authored andcommitted
Fix Wire memory leak
Signed-off-by: Benoit Malenfant <25072667+benmalenfant@users.noreply.github.com>
1 parent 3a3ff84 commit bd7f61a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 10 additions & 4 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy