Skip to content

Commit

Permalink
Merge pull request #49 from LeedanJohnson/master
Browse files Browse the repository at this point in the history
Fixed memory leak on repeated calls to 'EthernetClass::begin' using dhcp
  • Loading branch information
sstaub authored Jan 12, 2022
2 parents b332bac + 20c1dd4 commit 604d56f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Ethernet3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void EthernetClass::hardreset() {
int EthernetClass::begin(void)
{
uint8_t mac_address[6] ={0,};
_dhcp = new DhcpClass();
if (_dhcp == nullptr) {
_dhcp = new DhcpClass();
}

// Initialise the basic info
w5500.init(_maxSockNum, _pinCS);
Expand Down Expand Up @@ -108,7 +110,9 @@ void EthernetClass::begin(IPAddress local_ip, IPAddress subnet, IPAddress gatewa
#else
int EthernetClass::begin(uint8_t *mac_address)
{
_dhcp = new DhcpClass();
if (_dhcp == nullptr) {
_dhcp = new DhcpClass();
}
// Initialise the basic info
w5500.init(_maxSockNum, _pinCS);
w5500.setMACAddress(mac_address);
Expand Down

0 comments on commit 604d56f

Please sign in to comment.