Console - argtable leaks memory

duncairn
Posts: 8
Joined: Mon May 04, 2020 4:38 pm

Console - argtable leaks memory

Postby duncairn » Mon Dec 13, 2021 1:13 am

I am trying to implement some console commands and have a bunch working that don't use command line parameters. That is, they are simple single-word commands. However, if I introduce arguments to a command I get a 24-byte memory leak whenever it's run. Looking at the argtable tutorial, I see they call arg_freetable() when done. I tried also using it but the way the argtable[] is done in ESP-IDF is rather different.

Anyway, so then I decide to run the example console code to see if perhaps Espressif is doing something behind the scenes to tidy up. This if idf 4.2, which is what I am currently using. What happens is that every command seems to leak memory, not just those with parameters! However, if I run the same command twice there seems to be no leak... This is best explained with some example output:

Code: Select all

This is an example of ESP-IDF console component.
Type 'help' to get the list of commands.
Use UP/DOWN arrows to navigate through command history.
Press TAB when typing command name to auto-complete.
Your terminal application does not support escape sequences.
Line editing and history features are disabled.
On Windows, try using Putty instead.
esp32> free
Unrecognized command
258452 free
esp32> heap
I (40521) cmd_system: min heap size: 258440
esp32> free
258428
esp32> free
258428
esp32> heap
I (51121) cmd_system: min heap size: 258416
esp32> free
258404
esp32> heap
I (55521) cmd_system: min heap size: 258392
esp32> heap
I (57421) cmd_system: min heap size: 258392
esp32> free
258384
esp32>
(Note that I had to modify the example console app to add a newline after command entry, otherwise the result overwrites the command line - I think this is a bug, but perhaps it's intended.)

Anyone got an idea what's going on? Does arg_freetable() need to be called or not?

duncairn
Posts: 8
Joined: Mon May 04, 2020 4:38 pm

Re: Console - argtable leaks memory

Postby duncairn » Mon Dec 13, 2021 8:22 am

False alarm. The memory use is from this line:

Code: Select all

linenoiseHistoryAdd(line);
Comment that out and some commands cause a drop in free memory as they set up stuff (or call stuff) but that then remains static through further commands. More importantly, my code now works as expected, which is a plus :D

Who is online

Users browsing this forum: No registered users and 59 guests