Skip to content

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

@wengkai

Description

@wengkai

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: DuplicateAnother item already exists for this topic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions