Skip to content
This repository was archived by the owner on Jan 7, 2019. It is now read-only.

Commit ddf4036

Browse files
authored
Merge pull request #8 from Ivan-Perez/master
Fix memory leak
2 parents 0656036 + 470def0 commit ddf4036

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/Ethernet2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, };
2121
int EthernetClass::begin(void)
2222
{
2323
byte mac_address[6] ={0,};
24+
if (_dhcp != NULL) {
25+
delete _dhcp;
26+
}
2427
_dhcp = new DhcpClass();
2528

2629
// Initialise the basic info
@@ -78,6 +81,9 @@ void EthernetClass::begin(IPAddress local_ip, IPAddress dns_server, IPAddress ga
7881
#else
7982
int EthernetClass::begin(uint8_t *mac_address)
8083
{
84+
if (_dhcp != NULL) {
85+
delete _dhcp;
86+
}
8187
_dhcp = new DhcpClass();
8288
// Initialise the basic info
8389
w5500.init(w5500_cspin);

src/Ethernet2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class EthernetClass {
2929
static uint8_t _state[MAX_SOCK_NUM];
3030
static uint16_t _server_port[MAX_SOCK_NUM];
3131

32-
EthernetClass() { w5500_cspin = 10; }
32+
EthernetClass() { _dhcp = NULL; w5500_cspin = 10; }
3333
void init(uint8_t _cspin = 10) { w5500_cspin = _cspin; }
3434

3535
#if defined(WIZ550io_WITH_MACADDRESS)

0 commit comments

Comments
 (0)