From b01229e451289ae9c64c51897bfb70045227080b Mon Sep 17 00:00:00 2001 From: W-Mai <1341398182@qq.com> Date: Thu, 3 Nov 2022 19:48:21 +0800 Subject: [PATCH] fix(lv_flex): simplify mem alloc approach (#3781) Signed-off-by: xinbingnan Signed-off-by: W-Mai <1341398182@qq.com> --- src/layouts/flex/lv_flex.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/layouts/flex/lv_flex.c b/src/layouts/flex/lv_flex.c index 2472d9b45..34b595ad1 100644 --- a/src/layouts/flex/lv_flex.c +++ b/src/layouts/flex/lv_flex.c @@ -349,19 +349,15 @@ static int32_t find_track_end(lv_obj_t * cont, flex_t * f, int32_t item_start_id t->grow_item_cnt++; t->track_fix_main_size += item_gap; if(t->grow_dsc_calc) { - grow_dsc_t * new_dsc = lv_malloc(sizeof(grow_dsc_t) * (t->grow_item_cnt)); + grow_dsc_t * new_dsc = lv_realloc(t->grow_dsc, sizeof(grow_dsc_t) * (t->grow_item_cnt)); LV_ASSERT_MALLOC(new_dsc); if(new_dsc == NULL) return item_id; - if(t->grow_dsc) { - lv_memcpy(new_dsc, t->grow_dsc, sizeof(grow_dsc_t) * (t->grow_item_cnt - 1)); - lv_free(t->grow_dsc); - } new_dsc[t->grow_item_cnt - 1].item = item; - new_dsc[t->grow_item_cnt - 1].min_size = f->row ? lv_obj_get_style_min_width(item, - LV_PART_MAIN) : lv_obj_get_style_min_height(item, LV_PART_MAIN); - new_dsc[t->grow_item_cnt - 1].max_size = f->row ? lv_obj_get_style_max_width(item, - LV_PART_MAIN) : lv_obj_get_style_max_height(item, LV_PART_MAIN); + new_dsc[t->grow_item_cnt - 1].min_size = f->row ? lv_obj_get_style_min_width(item, LV_PART_MAIN) + : lv_obj_get_style_min_height(item, LV_PART_MAIN); + new_dsc[t->grow_item_cnt - 1].max_size = f->row ? lv_obj_get_style_max_width(item, LV_PART_MAIN) + : lv_obj_get_style_max_height(item, LV_PART_MAIN); new_dsc[t->grow_item_cnt - 1].grow_value = grow_value; new_dsc[t->grow_item_cnt - 1].clamped = 0; t->grow_dsc = new_dsc;