Page 1 of 1

Re: TLS storing previous connection information

Posted: Tue Mar 07, 2017 12:57 am
by ESP_Angus
This is just a possibility,but: When you close a TCP socket, LWIP needs to keep the socket around in the TIME_WAIT state until it knows the socket is closed at the other end.

This list shouldn't be bounded by size though, as far as I know it's only bounded by time. But if you are creating/deleting sockets on a regular basis, it may be that "10 sockets" is the amount of time it takes to timeout one socket.

Re: TLS storing previous connection information

Posted: Tue Aug 08, 2017 10:34 pm
by slcasner
The reason why 84 bytes are not freed when you close the socket is that LWIP allocates a mutex for use with each socket structure the first time the socket is opened and intentionally does not free that mutex. Look for the comment /* one time init and never free */ in esp-idf/components/lwip/api/sockets.c

The reason why this memory "leak" stops after the 10th time is that the default configuration (which you can change in menuconfig) provides space for 10 socket structures. LWIP follow as policy of not reusing a socket number and its associated structure so long as there is a never-used one still available. After all 10 have been used, then it will reuse one. In that case, the mutex will have already been allocated.