andyvand / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

memory leak in Ethernet.cpp (for version arduino-1.0.1). #1000

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Each call to EthernetClass::begin will create a new DhcpClass, which is 
assigned to the _dhcp member variable. This variable is never deleted, so each 
subsequent call to EthernetClass::begin will leak about 100 bytes. It takes 
about 10 calls to cause the Atmega328 to run out of memory.

My patch simply checks if _dhcp was already allocated. If already allocated 
then it reuses the previous _dhcp. As an alternative, the previous _dhcp member 
could be deleted and a new one allocated. This may be ensure that _dhcp is in a 
known, good state. This is probably safer; however, it seems that 
EthernetClass::begin correctly initializes _dhcp, so it seemed safe to reuse it 
in this case. Reusing _dhcp also requires fewer code changes.

I am using Arduino 1.0.1 with an Arduino Uno, Atmega328 and an Arduino Ethernet 
R3 shield.

I have attached a patch to Ethernet.cpp. This patch works in my application and 
it seems to cause no changes in the examples included with the Ethernet library.

I have also attached a simple test sketch that demonstrates the problem. This 
test sketch is a simple DHCP stress tester. It creates new MAC addresses and 
requests new IP address leases from DHCP.

Thanks!
Noah Spurrier <noah@noah.org>

Original issue reported on code.google.com by n...@noah.org on 31 Jul 2012 at 7:18

Attachments:

GoogleCodeExporter commented 9 years ago
This appears to be a duplicate of Issue #933. Sorry, I didn't search first. I 
even used practically the same summary!

Original comment by n...@noah.org on 1 Aug 2012 at 8:08

GoogleCodeExporter commented 9 years ago

Original comment by c.mag...@bug.st on 15 Dec 2012 at 11:57