-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TW#13918] lwip/netconn: Memory leak for netconn_delete() #784
Comments
I believe if you are using netconn api you have to handle thread safety on your own, so you decide when to call netconn_free and call it yourself. Otherwise, use socket api. |
This sounds familiar to the issue I mentioned here #537. Make sure you do not use lwip_... calls as they are not automatically mapped to the thread safe counterparts. |
Hi @devsaurus , The thread-safe socket layer made this change in order to support closing a BSD socket from one thread while a pending read/write was running in another. This behaviour change for netconn_close() API looks like an unintended consequence. Until we have a fix, the best workaround is probably to call netconn_free() after netconn_close(). Angus |
Thanks for the feedback, guys! I exclusively use netconn_ calls so the handover between my single-task application (the NodeMCU Lua firmware) and the lwip stack should be safe. I assume that this is also true for calling Somewhat off-topic: I found that I strictly have to avoid calling netconn_ functions from the application callback in tcpip-task context (registered with |
I was getting crazy with this memory leak. Thank you for pointing me to this line 176! |
Hi, We have also faced same memory leak issue while using netconn library at our side. so, what is the workaround or final fix for that issue? We are using netconn open/close/accept/listen all those APIs into our project development purpose. Please help us or any suggestions for that solution. |
Add a call to netconn_free after netconn_delete. |
Ok. Let me check and get back to you with updated result. |
@devsaurus @tonyp7 @Ritesh236 Sorry to reply so late, we have modified the code against your problem. After the MR is merged, you can see the change |
Hi, Thanks for Reply. So, Will that fix be included into ESP32 LWIP Library in which netconn APIs are defined? |
yes, it will be |
Hi, Thanks for providing update. It seems like you have fixed into ESP32 IDF on Git. Correct? I will check it and let you know if any issue. |
Hi, Also just want to confirm that now we don't need to call netconn_free after netconn_delete API as it has been fixed into LWIP code itself. Correct? |
@Ritesh236 yes, you are right |
…free(), which will lead to memory leak Closes #784
no longer necessary to call netcon_free since the memory leak was fixed with latest version of esp-idf
Well spotted on line 176!!! that was driving me crazy |
@Designer-Rick Did you test with the latest esp-idf ? Please post your commit ID and your error log, thanks! |
I'm evaluating the lwip netconn API and investigate some memory leaks with closed connections.
My application code assumes that a call to
netconn_delete()
finally frees all resources, but I observe that this is not true. I need to remove the#if !ESP_THREAD_SAFE
in line 176 to get heap to return to initial level. Otherwise, each accept/send/close/delete cycle on a server netconn leaks ~70 bytes of heap memory. Similar for client connections.What was the rationale to disable
netconn_free()
in case ofESP_THREAD_SAFE
configuration? If it's required, how to fix the memory leak whennetconn_free()
is not executed - Is there a thread-safe method to free it?The text was updated successfully, but these errors were encountered: