-->
Page 3 of 3

Re: Memory Leak in ESP8266WebServer

PostPosted: Sat Jun 27, 2015 9:12 am
by Lucaspp
ReinholdHiller wrote:In clientcontext.h I changed line 70 and following (the following if ()... is now useless, but for a test.) to:

err = tcp_close(_pcb);
tcp_abort(_pcb);
if(err != ERR_OK) {

This fixes the "memory leak" and does not seem to harm the Webserver example.


Thanks for helps us in this forum. You are making very good job. There is a new ClientContext.h version and I cannot find where I have to change it.

Could somebody help me to get the right place in the new version?

Thanks and best regards

Re: Memory Leak in ESP8266WebServer

PostPosted: Mon Jun 29, 2015 2:50 pm
by Lucaspp
ReinholdHiller wrote:In clientcontext.h I changed line 70 and following (the following if ()... is now useless, but for a test.) to:

err = tcp_close(_pcb);
tcp_abort(_pcb);
if(err != ERR_OK) {

This fixes the "memory leak" and does not seem to harm the Webserver example.


Thanks for your help. I could figure it out. Modification is made for the current file release at line 64.

ClientContext.h

64 err = tcp_close(_pcb);
65 tcp_abort(_pcb); // Modification 28-06-2015
66 if(err != ERR_OK) {
67 DEBUGV(":tc err %d\r\n", err);
68 tcp_abort(_pcb);
69 err = ERR_ABRT;

Very good Jop.

Best regards

Re: Memory Leak in ESP8266WebServer

PostPosted: Sat Oct 19, 2019 9:26 pm
by Serge M
As for now both esp32, esp8266 cores have same issue with memory leaks caused by internal arrays _postArgs, _currentArgs which never disposed. Authors should start at junior positions... :lol:

To work around one may want to inherit from ESP8266WebSever class (or WebServer with esp32) and inplement a destructor similar to this:

virtual ~MyWebServer()
{
if (this->_currentArgs)
{
delete[] this->_currentArgs;
this->_currentArgs = nullptr;
}

if (this->_postArgs)
{
delete[] this->_postArgs;
this->_postArgs = nullptr;
}
}

That's it.