Netconn memory leak issue

mpulis
Posts: 57
Joined: Mon Aug 07, 2017 7:53 am

Netconn memory leak issue

Postby mpulis » Thu Dec 21, 2017 10:18 am

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?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Netconn memory leak issue

Postby ESP_Angus » Fri Dec 22, 2017 1:31 am

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.

mpulis
Posts: 57
Joined: Mon Aug 07, 2017 7:53 am

Re: Netconn memory leak issue

Postby mpulis » Fri Dec 22, 2017 9:15 am

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!

Who is online

Users browsing this forum: akasaka_spk, axellin and 57 guests