From cce70d269c23e9985fe970378fb6dd209b576643 Mon Sep 17 00:00:00 2001 From: Richard Sim Date: Sun, 2 Dec 2012 22:39:34 -0800 Subject: [PATCH] * Fixed memory leak when calling Ethernet.begin() multiple times * Ensure the UDP socket is closed before trying to open it --- libraries/Ethernet/Dhcp.cpp | 1 + libraries/Ethernet/Ethernet.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/Ethernet/Dhcp.cpp b/libraries/Ethernet/Dhcp.cpp index e4d27f722..56d5b6951 100755 --- a/libraries/Ethernet/Dhcp.cpp +++ b/libraries/Ethernet/Dhcp.cpp @@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){ _dhcpTransactionId = random(1UL, 2000UL); _dhcpInitialTransactionId = _dhcpTransactionId; + _dhcpUdpSocket.stop(); if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0) { // Couldn't get a socket diff --git a/libraries/Ethernet/Ethernet.cpp b/libraries/Ethernet/Ethernet.cpp index 5d28f71f9..c31a85f09 100644 --- a/libraries/Ethernet/Ethernet.cpp +++ b/libraries/Ethernet/Ethernet.cpp @@ -10,7 +10,8 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { int EthernetClass::begin(uint8_t *mac_address) { - _dhcp = new DhcpClass(); + static DhcpClass s_dhcp; + _dhcp = &s_dhcp; // Initialise the basic info