buglwIP - A Lightweight TCP/IP stack - Bugs: bug #60758, Provide a way to release all memory


You are not allowed to post comments on this tracker with your current authentication level.

bug #60758: Provide a way to release all memory

Submitter:  R. Diez <rdiez>
Submitted:  Wed 09 Jun 2021 06:55:04 PM UTC
Category:  None Severity:  3 - Normal
Item Group:  Feature Request Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Planned Release:  None
lwIP version:  git head

Thu 10 Jun 2021 08:22:51 AM UTC, comment #2: 

> No, callign al timeout handlers will definitively not be enough.

Could you elaborate more?

I do not know much about lwIP's internals, so I can only describe the naive train of thought: if I remove all network interfaces and make everything time-out (perhaps by artificially moving the current time far into the future), wouldn't all connections and PCBs (listening or not) be automatically destroyed? What resources would remain then?

That information will probably be useful not just for future implementers: if I know what to expect, I could code an exception, so that those memory blocks are skipped from the final memory leak report.

> As long as you don't know exactly how this one
> would be easier as bug #55598 (clean shutdown)

I cannot know that 'exactly', because I am not familiar lwIP's internals.

The "clean shutdown" bug talks about being able to restart. Normally, that is harder to achieve than providing a termination routine.

Such a routine could just release all malloc() memory and not bother to reset everything for an eventual restart. The documentation could state that lwIP is afterwards not stable, so that calling any other lwIP function is likely to crash.

But if you know better, you can close this bug yourself.

There is one more aspect: one could implement clean termination and restart, and still not release all memory. For example, the restarted lwIP could re-use some old memory pools that are still hanging around.

> It would be better off in the "tasks" section.

I do not know what "tasks" section you are talking about, but yes, I gather that you could move it there and close this feature request as "moved to the tasks section".

R. Diez <rdiez>
Thu 10 Jun 2021 06:46:42 AM UTC, comment #1: 

No, callign al timeout handlers will definitively not be enough. As long as you don't know exactly how this one would be easier as bug #55598 (clean shutdown), could we please close this as duplicate? We have too many bugs open here, and this one isn't even a bug. It would be better off in the "tasks" section.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 09 Jun 2021 06:55:04 PM UTC, original submission:  

I recently asked the following question in the lwip-users mailing list:

How to release all memory to track leaks

From the answers I got, I gather that there is no way to do that at the moment, so I decided to create a feature request for it.

I have a bare-metal (Newlib, no threads) firmware that uses lwIP and its httpd server to provide a simple web interface.

The firmware is actually quite complex in other areas. I am trying to identify and track down eventual memory leaks, so I implemented a "shutdown" command in the debug console that releases all resources and checks the remaining allocated bytes with mallinfo().

I suspect some of the remaining memory "leaks" belong to lwIP and/or its httpd server, because they only come up after having downloaded the web page once. They probably are not real leaks, because memory usage does not grow over time.

It is hard to say, because it is not easy to track memory allocations with Newlib. Or at least I haven't mastered it yet.

In any case, I would like lwIP to release all memory on shutdown, in order to locate any memory leaks in other parts. The trouble is, there are routines like lwip_init() and httpd_init(), but no xxx_terminate() counterparts.

I tried removing all interfaces with netif_remove(), but that is apparently not enough.

This is a serious limitation, because it effectively prevents me from automatically detecting memory leaks in my firmware.

Other libraries have identified this need and provided a way to do it. For example, glibc provides __libc_freeres, and GCC's C++ support library provides __gnu_cxx::__freeres.

There is another feature request that is somewhat related:

Clean shutdown and restart support

That is about providing a complete lwIP shutdown and restart, but I do not need to go that far. I just need dynamic memory to be released, which could be much easier to achieve.

I wonder whether one could artificially move the internal time forwards (far in the future) and tick all lwIP state machines once more after all interfaces have been removed. Could that effectively trigger all possible timeouts and do a complete memory release all over the place? Or would such a trick still not be enough?

R. Diez <rdiez>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by rdiez (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.


    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-f762.
    Corresponding source code