ESP32-S3 stack leak with variables (VSCode, ESP-IDF)
Posted: Thu Jun 12, 2025 4:01 pm
We detected a stack leak in something that was not supposed.
It only occurs in the first call to a function, not in the following calls.
We reduced the problem to a simpler example that everyone can test:
Example 1:
Calling this function in task in task main
Before running function:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4
After:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4 ----> OK
No change in available free memory in task --> OK
/-------------------------------------------------------------------------------------------------------------------
Example 2:
Calling this 2nd function in task main
Before running function:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4
After:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 4912 4 ---> NOK
The task "free memory" never recovers to the previous value.
Calling the function again does not decrease the free memory any further.
Any ideas of what is wrong?
It only occurs in the first call to a function, not in the following calls.
We reduced the problem to a simpler example that everyone can test:
Example 1:
Calling this function in task in task main
Code: Select all
void test_main() {
char test[500] = {0};
}Before running function:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4
After:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4 ----> OK
No change in available free memory in task --> OK
/-------------------------------------------------------------------------------------------------------------------
Example 2:
Calling this 2nd function in task main
Code: Select all
void test_main() {
char test[500] = {0};
printf("\n->TEST MEM");
}Before running function:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 5248 4
After:
.----------+-------+----------+-------+------
| Process | STATE | PRIORITY | FREE | PID
'----------+-------+----------+-------+------
main X 1 4912 4 ---> NOK
The task "free memory" never recovers to the previous value.
Calling the function again does not decrease the free memory any further.
Any ideas of what is wrong?