Page 1 of 1

IDF中的CONSOLE组件内存泄漏

Posted: Mon Mar 11, 2019 3:41 am
by aureoleday
在CONSOLE中输入tasks,help等指令后,调用free查看剩余内存发现递减。
而free指令本身不会造成内存泄漏

Re: IDF中的CONSOLE组件内存泄漏

Posted: Thu Mar 21, 2019 12:13 pm
by ESP_igrr
This is due to the way console history feature works.

When new command is typed, and the command is not the same as the previous command, it is added to history. If it is the same as the previous command, it is not added to history. Adding a command to history requires allocating memory for the command string (strdup). Therefore:

free <- gets added to history, allocate 5 bytes (actual heap size is reduced by 12 bytes due to metadata and alignment)
-> (reports heap value)
free <- does not get added to history, because is the same as last command
-> (reports same heap value)

But

free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value (after the allocation)
help <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> prints help
free <- gets added to history, allocate 5 bytes, heap is reduced by 12 bytes
-> reports heap value, which is less than the previous one by 24 bytes (due to the last two allocations)

None of these strings are leaked, though. When the history buffer becomes full, old items will be deleted. They will also be deleted if you call linenoiseHistoryFree().

If you don't wish to store history, you can disable it using CONFIG_STORE_HISTORY.

Re: IDF中的CONSOLE组件内存泄漏

Posted: Tue Apr 09, 2019 6:59 am
by aureoleday
解释得非常清楚,感谢!