Question: I'm using lwIP on an embedded device, and I feel that I may be running into some bugs related to running out of memory. I know that the mem\_malloc function itself will return null when a memory allocation fails, but is there any way to get a rough assessment of the available memory at an arbitrary point in time? It would be great to be able to monitor it directly, to determine which usage patterns are leaking memory.

Thanks.

Answer: 
Define MEM\_STATS and look at the memory statistics via stats\_display\_mem. See stats.h, stats.c, and opt.h among other places. That should get you started.
In LwIP version 2.1.3, You need to define MEM\_STATS, but also LWIP\_STATS. To output the stats, when you have defined LWIP\_STATS\_DISPLAY, you can use MEM\_STATS\_DISPLAY().