mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Prevent crash on update value_Str
This commit is contained in:
parent
26708d7dc8
commit
7d841a06e1
@ -170,14 +170,27 @@ static lv_font_t * haspPayloadToFont(const char * payload)
|
|||||||
return &unscii_8_icon;
|
return &unscii_8_icon;
|
||||||
|
|
||||||
#if ESP32
|
#if ESP32
|
||||||
|
|
||||||
|
#if LV_FONT_MONTSERRAT_12 > 0
|
||||||
case 12:
|
case 12:
|
||||||
return &lv_font_montserrat_12;
|
return &lv_font_montserrat_12;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_FONT_MONTSERRAT_16 > 0
|
||||||
case 16:
|
case 16:
|
||||||
return &lv_font_montserrat_16;
|
return &lv_font_montserrat_16;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_FONT_MONTSERRAT_22 > 0
|
||||||
case 22:
|
case 22:
|
||||||
return &lv_font_montserrat_22;
|
return &lv_font_montserrat_22;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if LV_FONT_MONTSERRAT_28 > 0
|
||||||
case 28:
|
case 28:
|
||||||
return &lv_font_montserrat_28_compressed;
|
return &lv_font_montserrat_28_compressed;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -536,19 +549,20 @@ static void hasp_local_style_attr(lv_obj_t * obj, const char * attr_p, uint16_t
|
|||||||
return attribute_value_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
|
return attribute_value_opa(obj, part, state, update, attr_p, (lv_opa_t)var);
|
||||||
case ATTR_VALUE_STR: {
|
case ATTR_VALUE_STR: {
|
||||||
if(update) {
|
if(update) {
|
||||||
// Free previous string
|
|
||||||
const char * str = lv_obj_get_style_value_str(obj, part);
|
|
||||||
lv_obj_set_style_local_value_str(obj, part, state, NULL);
|
|
||||||
lv_mem_free(str);
|
|
||||||
|
|
||||||
// Create new string
|
|
||||||
size_t len = strlen(payload);
|
size_t len = strlen(payload);
|
||||||
if(len > 0) {
|
if(len > 0) {
|
||||||
|
// Free previous string
|
||||||
|
const char * str = lv_obj_get_style_value_str(obj, part);
|
||||||
|
|
||||||
|
// Create new string
|
||||||
len++;
|
len++;
|
||||||
char * str_p = (char *)lv_mem_alloc(len);
|
char * str_p = (char *)lv_mem_alloc(len);
|
||||||
memset(str_p, 0, len);
|
memset(str_p, 0, len);
|
||||||
memccpy(str_p, payload, 0, len);
|
memccpy(str_p, payload, 0, len);
|
||||||
lv_obj_set_style_local_value_str(obj, part, state, str_p);
|
lv_obj_set_style_local_value_str(obj, part, state, str_p);
|
||||||
|
|
||||||
|
// if(strlen(str) > 0) lv_mem_free(str); // BIG : Memory Leak ! / crashes
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hasp_out_str(obj, attr, lv_obj_get_style_value_str(obj, part));
|
hasp_out_str(obj, attr, lv_obj_get_style_value_str(obj, part));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user