From 96e2f879523960540fffc10092a6b92ed70941c7 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 21 Jan 2020 22:32:25 +0100 Subject: [PATCH] fix mem leak in bidi --- src/lv_draw/lv_draw_label.c | 2 ++ src/lv_draw/lv_draw_rect.c | 2 ++ src/lv_misc/lv_bidi.c | 11 ++++++++--- src/lv_misc/lv_mem.c | 4 +++- src/lv_objx/lv_label.c | 2 +- src/lv_objx/lv_roller.c | 4 +++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/lv_draw/lv_draw_label.c b/src/lv_draw/lv_draw_label.c index 529fb2252..3f8d9ce83 100644 --- a/src/lv_draw/lv_draw_label.c +++ b/src/lv_draw/lv_draw_label.c @@ -336,6 +336,8 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab if(pos.y > mask->y2) return; } + + lv_mem_test(); } /********************** diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index 86be84d0b..f544af712 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -72,6 +72,8 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect draw_bg(coords, clip, dsc); draw_img(coords, clip, dsc); draw_border(coords, clip, dsc); + + lv_mem_test(); } /** diff --git a/src/lv_misc/lv_bidi.c b/src/lv_misc/lv_bidi.c index f38afdea0..8dbc1c9a8 100644 --- a/src/lv_misc/lv_bidi.c +++ b/src/lv_misc/lv_bidi.c @@ -187,13 +187,15 @@ bool lv_bidi_letter_is_neutral(uint32_t letter) */ uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, uint32_t visual_pos, bool *is_rtl) { - uint32_t pos_conv_len = get_txt_len(str_in, len); char * buf = lv_mem_buf_get(len + 1); if(buf == NULL) return (uint16_t) -1; uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); - if(pos_conv_buf == NULL) return (uint16_t) -1; + if(pos_conv_buf == NULL) { + lv_mem_buf_release(buf); + return (uint16_t) -1; + } if (bidi_txt) *bidi_txt = buf; @@ -226,7 +228,10 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t l if(buf == NULL) return (uint16_t) -1; uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); - if(pos_conv_buf == NULL) return (uint16_t) -1; + if(pos_conv_buf == NULL) { + lv_mem_buf_release(buf); + return (uint16_t) -1; + } if (bidi_txt) *bidi_txt = buf; diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 4f4351dd2..9f2302015 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -356,7 +356,7 @@ lv_res_t lv_mem_test(void) lv_mem_ent_t * e; e = ent_get_next(NULL); while(e) { - if(e->header.s.d_size > 200000) { + if(e->header.s.d_size > 20000) { printf("mem err\n"); while(1); return LV_RES_INV; @@ -435,6 +435,8 @@ uint32_t lv_mem_get_size(const void * data) */ void * lv_mem_buf_get(uint32_t size) { + if(size == 0) return NULL; + /*Try to find a free buffer with suitable size */ uint8_t i; for(i = 0; i < LV_MEM_BUF_MAX_NUM; i++) { diff --git a/src/lv_objx/lv_label.c b/src/lv_objx/lv_label.c index 8b9592bc5..ffd11f2d1 100644 --- a/src/lv_objx/lv_label.c +++ b/src/lv_objx/lv_label.c @@ -709,7 +709,7 @@ uint16_t lv_label_get_letter_on(const lv_obj_t * label, lv_point_t * pos) #if LV_USE_BIDI bidi_txt = lv_mem_buf_get(new_line_start - line_start + 1); uint16_t txt_len = new_line_start - line_start; - if(bidi_txt[new_line_start] == '\0') txt_len--; + if(bidi_txt[new_line_start] == '\0' && txt_len > 0) txt_len--; lv_bidi_process_paragraph(txt + line_start, bidi_txt, txt_len, lv_obj_get_base_dir(label), NULL, 0); #else bidi_txt = (char*)txt + line_start; diff --git a/src/lv_objx/lv_roller.c b/src/lv_objx/lv_roller.c index e7a17ad6d..0e1c42f03 100644 --- a/src/lv_objx/lv_roller.c +++ b/src/lv_objx/lv_roller.c @@ -218,7 +218,9 @@ void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, lv_anim_enable_ anim = LV_ANIM_OFF; #endif - if(lv_roller_get_selected(roller) == sel_opt) return; + /* Set the value even if it's the same as the current value because + * if moving to the next option with an animation which was just deleted in the PRESS signal + * nothing will continue the animation. */ lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); ext->sel_opt_id = sel_opt < ext->option_cnt ? sel_opt : ext->option_cnt - 1;