lvgl: [ESP32] Memory corruption under certain multithreading-related circumstances
char * string_text = malloc(size_text + 1);
//removed some codes here that sets content of string_text, because it's not lvgl related
string_text[size_text] = '\0';
lv_label_set_text(label, string_text);
free(string_text);
When periodically set the text for a label, it will crashed at the line 123 of file lv_draw_label.c. Because the arg txt is NULL. The crashing time is random, it can be a few minutes up to an hour. The text is set every second.
if(txt[0] == '\0') return;
The issue solved by the following code
if(txt == NULL || txt[0] == '\0') return;
LVGL revision V7.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 48 (22 by maintainers)
It would be better to figure out why
txt
isNULL
in the first place; your solution is more of a workaround. My guess is that you’re running out of memory and thus allocation of a text buffer fails somewhere.Hi @weixiongmei,
cc @embeddedt, @kisvegabor
I have taken a look at the ESP32 FreeRTOS implementation and it seems the developers have kind of done their own thing with it.
Firstly they have created their own SMP version of FreeRTOS which I am not at all familiar with and is unique to them. I dug into the source files a bit and as far as memory management goes they are using the newlib C library and they have implemented it with support for reentrancy so on that basis it should be fine to use the malloc() and free() (also printf etc.) calls in the multi-threaded/task environment. So I would think we can probably safely discount that as a source of potential problems in your code.
Kind Regards,
Pete