Page 1 of 1

Netconn memory leak issue

Posted: Thu Dec 21, 2017 10:18 am
by mpulis
Hi all,

I'm working on a project using the ESP32 and the netconn api. While servicing incoming data on a connection, I've observed a continuous memory leak of 40 bytes on each iteration of a while loop.

I've commented out most of the code in order to trace the issue until all that remained from the original code was the below featured code. Apparently the issue is coming from the netconn_recv function, as on commenting that out there are no more memory leaks.

Code: Select all

while (1)
{
	inbuf = netbuf_new();
	err = netconn_recv(conn, &inbuf);
	ESP_LOGE(TAG, "Remaining space on RAM: %d", esp_get_free_heap_size());
	netbuf_delete(inbuf);
}
I don't see any reason for the memory leak. Can someone enlighten me about this issue?

Re: Netconn memory leak issue

Posted: Fri Dec 22, 2017 1:31 am
by ESP_Angus
netconn_recv() allocates the new netbuf that it returns, so it's replacing the empty netbuf allocated on the first line with a new one. So the original (empty) one is leaked.

If you remove the first line (inbuf = netbuf_new();), then the leak should go away.

Re: Netconn memory leak issue

Posted: Fri Dec 22, 2017 9:15 am
by mpulis
Ah brilliant, that seems to have solved the issue! There still is a memory leak in another part of the code, which I assume is coming from the netconn_accept() function.

Thankyou very much!