Ethernet.setup() has a leak at re-entering this function #1200

Closed
wengkai opened this Issue Jan 5, 2013 · 1 comment

Comments

3 participants

wengkai commented Jan 5, 2013

This may be a bug in the official Ethernet library which comes along with the Arduino IDE.

In the class Ethernet, there is a setup() function which is used to init the hardware and, in case of DHCP configure, get the DHCP address and settings. In this setup() function, a new object of DHCP will be created and assigned to the dhcp member variable, which is a pointer.

The problem occurs when the Arduino loses its DHCP settings, e.g. for a limited DHCP live time issued by the DHCP server. Then the skecth has to find a way to re-apply for a DHCP assignment and there's no other functions providing such service. It seems to be workable if you call the setup() function again.
But what really happens inside this setup() is it never delete the old DHCP object and tries to create a new one. It works fine if your sketch tries 5 or 6 times, and then, there will be no enough space to create another DHCP object. And your sketch will not get a DHCP address anymore.

That's why some Arduino network projects can not work 24X7.

The solution is very simple. Add this line at the beginning of this setup() function:
if ( dhcp ) delete dhcp;
Have fun!

Owner

cmaglie commented Jan 6, 2013

This is a duplicate of #933 that was already solved. The fix will be available on 1.0.4.

Would you like to check if the fix works for you? Here the patch:
cce70d2

@cmaglie cmaglie closed this Jan 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment