Skip to content

Commit cce70d2

Browse files
richard-simcmaglie
authored andcommitted
* Fixed memory leak when calling Ethernet.begin() multiple times
* Ensure the UDP socket is closed before trying to open it
1 parent 6dbc2bf commit cce70d2

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

libraries/Ethernet/Dhcp.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){
4343
_dhcpTransactionId = random(1UL, 2000UL);
4444
_dhcpInitialTransactionId = _dhcpTransactionId;
4545

46+
_dhcpUdpSocket.stop();
4647
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
4748
{
4849
// Couldn't get a socket

libraries/Ethernet/Ethernet.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
1010

1111
int EthernetClass::begin(uint8_t *mac_address)
1212
{
13-
_dhcp = new DhcpClass();
13+
static DhcpClass s_dhcp;
14+
_dhcp = &s_dhcp;
1415

1516

1617
// Initialise the basic info

0 commit comments

Comments
 (0)