Re: Memory leak in DHCP process

bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org Wed, 9 Oct 2019 11:04:16 +0200
Newsgroups gmane.comp.hardware.microcontrollers.ethernut
Message-ID <[email protected]>
J=F6rg 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.=A0
> =

> 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-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org

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 =3D 0;
             dhcpApiTimeout =3D NUT_WAIT_INFINITE;
             NutEventBroadcast(&dhcpDone);
+            /* Release Memory for routes */
+            if(dhcpDev!=3D0) {
+                NutIpRouteDelAll(dhcpDev); /* Release routes to allow free=
*/
+            }
             NutEventWait(&dhcpWake, NUT_WAIT_INFINITE);
         }
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion