[En-Nut-Discussion] Memory leak in DHCP process

bon at elektron.ikp.physik.tu-darmstadt.de bon at elektron.ikp.physik.tu-darmstadt.de
Wed Oct 9 11:04:16 CEST 2019


Jörg Wiegelmann writes:
> Dear folks,
> 
> I'm hunting a very seldom shutdown of a ethernut application. After a
> very long journey, I think I found a problem in the Nut OS DHCP logic. 
> 
> After the DHCP Lease time the Ethernut client is rebinding to the DHCP
> Server. In this process the application is calling the NutDhcpIfConfig
> function.
> This function looses memory in this way:
> 
> NutDhcpIfConfig->NutDhcpIfConfig2->NutNetIfSetup->NutIpRouteAdd->malloc
> without free!!!!
> 
> It's around 48 bytes with every call. To avoid this I changed the
> NutOs-DHCP-Client in this way (marked with >).
> 
> With this modification we don't loosing memory anymore.
> 
> Comments to this are welcome! I hope anyone is listening to this group.
> NutOs is a great system, but where is anybody ;-) ? On the Linux planet
> or on freeRtos or... ?
> 
Thanks fot hunting down that bug.

Please check that appended diff is what you intended and give feedback
before I appy to master.

Providing a real patch would help not not make editing errors.

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
diff --git a/nut/pro/dhcpc.c b/nut/pro/dhcpc.c
index 58f33b91c..4c4fdecfd 100644
--- a/nut/pro/dhcpc.c
+++ b/nut/pro/dhcpc.c
@@ -1734,6 +1734,10 @@ THREAD(NutDhcpClient, arg)
             retries = 0;
             dhcpApiTimeout = NUT_WAIT_INFINITE;
             NutEventBroadcast(&dhcpDone);
+            /* Release Memory for routes */
+            if(dhcpDev!=0) {
+                NutIpRouteDelAll(dhcpDev); /* Release routes to allow free*/
+            }
             NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
         }


More information about the En-Nut-Discussion mailing list