fix(leak): fix common memory leak on lv_init (#4750)

Signed-off-by: XiaoweiYan <yanxiaowei@xiaomi.com>
Co-authored-by: XiaoweiYan <yanxiaowei@xiaomi.com>
This commit is contained in:
bjsylvia
2023-11-06 21:55:52 +08:00
committed by GitHub
parent 361663ee5f
commit fbb65d2fe3
33 changed files with 221 additions and 3 deletions

View File

@@ -48,6 +48,11 @@ void _lv_group_init(void)
_lv_ll_init(group_ll_p, sizeof(lv_group_t));
}
void _lv_group_deinit(void)
{
_lv_ll_clear(group_ll_p);
}
lv_group_t * lv_group_create(void)
{
lv_group_t * group = _lv_ll_ins_head(group_ll_p);

View File

@@ -97,6 +97,12 @@ typedef enum {
*/
void _lv_group_init(void);
/**
* Deinit. the group module
* @remarks Internal function, do not call directly.
*/
void _lv_group_deinit(void);
/**
* Create a new object group
* @return pointer to the new object group

View File

@@ -79,6 +79,11 @@ void _lv_obj_style_init(void)
_lv_ll_init(style_trans_ll_p, sizeof(trans_t));
}
void _lv_obj_style_deinit(void)
{
_lv_ll_clear(style_trans_ll_p);
}
void lv_obj_add_style(lv_obj_t * obj, const lv_style_t * style, lv_style_selector_t selector)
{
LV_ASSERT(obj->style_cnt < 63);

View File

@@ -75,6 +75,12 @@ typedef struct {
*/
void _lv_obj_style_init(void);
/**
* Deinitialize the object related style manager module.
* Called by LVGL in `lv_deinit()`
*/
void _lv_obj_style_deinit(void);
/**
* Add a style to an object.
* @param obj pointer to an object

View File

@@ -70,6 +70,10 @@ void _lv_refr_init(void)
{
}
void _lv_refr_deinit(void)
{
}
void lv_refr_now(lv_display_t * disp)
{
lv_anim_refr_now();

View File

@@ -46,6 +46,11 @@ extern "C" {
*/
void _lv_refr_init(void);
/**
* Deinitialize the screen refresh subsystem
*/
void _lv_refr_deinit(void);
/**
* Redraw the invalidated areas now.
* Normally the redrawing is periodically executed in `lv_timer_handler` but a long blocking process

View File

@@ -50,6 +50,23 @@ void lv_draw_init(void)
#endif
}
void lv_draw_deinit(void)
{
#if LV_USE_OS
lv_thread_sync_delete(&_draw_info.sync);
#endif
lv_draw_unit_t * u = _draw_info.unit_head;
while(u) {
lv_draw_unit_t * cur_unit = u;
u = u->next;
if(cur_unit->delete_cb) cur_unit->delete_cb(cur_unit);
lv_free(cur_unit);
}
_draw_info.unit_head = NULL;
}
void * lv_draw_create_unit(size_t size)
{
lv_draw_unit_t * new_unit = lv_malloc(size);

View File

@@ -129,6 +129,13 @@ typedef struct _lv_draw_unit_t {
* @return
*/
int32_t (*evaluate_cb)(struct _lv_draw_unit_t * draw_unit, lv_draw_task_t * task);
/**
* Called to delete draw unit.
* @param draw_unit
* @return
*/
int32_t (*delete_cb)(struct _lv_draw_unit_t * draw_unit);
} lv_draw_unit_t;
@@ -190,6 +197,8 @@ typedef struct {
void lv_draw_init(void);
void lv_draw_deinit(void);
/**
* Allocate a new draw unit with the given size and appends it to the list of draw units
* @param size the size to allocate. E.g. `sizeof(my_draw_unit_t)`,

View File

@@ -74,6 +74,14 @@ void _lv_image_decoder_init(void)
lv_image_decoder_set_close_cb(decoder, lv_image_decoder_built_in_close);
}
/**
* Deinitialize the image decoder module
*/
void _lv_image_decoder_deinit(void)
{
_lv_ll_clear(img_decoder_ll_p);
}
/**
* Get information about an image.
* Try the created image decoder one by one. Once one is able to get info that info will be used.

View File

@@ -146,6 +146,11 @@ typedef struct _lv_image_decoder_dsc_t {
*/
void _lv_image_decoder_init(void);
/**
* Deinitialize the image decoder module
*/
void _lv_image_decoder_deinit(void);
/**
* Get information about an image.
* Try the created image decoder one by one. Once one is able to get info that info will be used.

View File

@@ -83,6 +83,11 @@ void lv_draw_pxp_init(void)
#endif
}
void lv_draw_pxp_deinit(void)
{
lv_pxp_deinit();
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -53,6 +53,8 @@ void lv_draw_buf_pxp_init_handlers(void);
void lv_draw_pxp_init(void);
void lv_draw_pxp_deinit(void);
void lv_draw_pxp_bg_img(lv_draw_unit_t * draw_unit, const lv_draw_bg_image_dsc_t * dsc,
const lv_area_t * coords);

View File

@@ -104,6 +104,10 @@ void lv_draw_vglite_init(void)
#endif
}
void lv_draw_vglite_deinit(void)
{
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -66,6 +66,8 @@ void lv_draw_buf_vglite_init_handlers(void);
void lv_draw_vglite_init(void);
void lv_draw_vglite_deinit(void);
void lv_draw_vglite_arc(lv_draw_unit_t * draw_unit, const lv_draw_arc_dsc_t * dsc,
const lv_area_t * coords);

View File

@@ -34,6 +34,7 @@
static void execute_drawing(lv_draw_sw_unit_t * u);
static int32_t lv_draw_sw_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer);
static int32_t lv_draw_sw_delete(lv_draw_unit_t * draw_unit);
/**********************
* STATIC VARIABLES
@@ -60,6 +61,7 @@ void lv_draw_sw_init(void)
lv_draw_sw_unit_t * draw_sw_unit = lv_draw_create_unit(sizeof(lv_draw_sw_unit_t));
draw_sw_unit->base_unit.dispatch_cb = lv_draw_sw_dispatch;
draw_sw_unit->idx = i;
draw_sw_unit->base_unit.delete_cb = LV_USE_OS ? lv_draw_sw_delete : NULL;
#if LV_USE_OS
lv_thread_init(&draw_sw_unit->thread, LV_THREAD_PRIO_HIGH, render_thread_cb, 8 * 1024, draw_sw_unit);
@@ -67,6 +69,24 @@ void lv_draw_sw_init(void)
}
}
void lv_draw_sw_deinit(void)
{
#if LV_DRAW_SW_COMPLEX == 1
lv_draw_sw_mask_deinit();
#endif
}
static int32_t lv_draw_sw_delete(lv_draw_unit_t * draw_unit)
{
#if LV_USE_OS
lv_draw_sw_unit_t * draw_sw_unit = (lv_draw_sw_unit_t *) draw_unit;
return lv_thread_delete(&draw_sw_unit->thread);
#else
LV_UNUSED(draw_unit);
return 0;
#endif
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -53,6 +53,8 @@ typedef struct {
void lv_draw_sw_init(void);
void lv_draw_sw_deinit(void);
LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_image(lv_draw_unit_t * draw_unit, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords);

View File

@@ -82,6 +82,10 @@ void lv_draw_sw_mask_init(void)
lv_mutex_init(&circle_cache_mutex);
}
void lv_draw_sw_mask_deinit(void)
{
lv_mutex_delete(&circle_cache_mutex);
}
LV_ATTRIBUTE_FAST_MEM lv_draw_sw_mask_res_t lv_draw_sw_mask_apply(void * masks[], lv_opa_t * mask_buf, int32_t abs_x,
int32_t abs_y,

View File

@@ -188,6 +188,8 @@ typedef struct _lv_draw_sw_mask_map_param_t {
void lv_draw_sw_mask_init(void);
void lv_draw_sw_mask_deinit(void);
//! @cond Doxygen_Suppress
/**

View File

@@ -50,6 +50,11 @@ void _lv_layout_init(void)
#endif
}
void _lv_layout_deinit(void)
{
lv_free(layout_list_def);
}
uint32_t lv_layout_register(lv_layout_update_cb_t cb, void * user_data)
{
layout_list_def = lv_realloc(layout_list_def, (layout_cnt + 1) * sizeof(lv_layout_dsc_t));

View File

@@ -53,6 +53,8 @@ typedef enum {
void _lv_layout_init(void);
void _lv_layout_deinit(void);
/**
* Register a new layout
* @param cb the layout update callback

View File

@@ -59,6 +59,17 @@ void lv_bmp_init(void)
lv_image_decoder_set_close_cb(dec, decoder_close);
}
void lv_bmp_deinit(void)
{
lv_image_decoder_t * dec = NULL;
while((dec = lv_image_decoder_get_next(dec)) != NULL) {
if(dec->info_cb == decoder_info) {
lv_image_decoder_delete(dec);
break;
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -28,6 +28,7 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
void lv_bmp_init(void);
void lv_bmp_deinit(void);
/**********************
* MACROS

View File

@@ -302,15 +302,54 @@ void lv_deinit(void)
lv_theme_mono_deinit();
#endif
_lv_cache_builtin_deinit();
_lv_cache_deinit();
_lv_image_decoder_deinit();
_lv_refr_deinit();
_lv_obj_style_deinit();
#if LV_USE_DRAW_PXP
lv_draw_pxp_deinit();
#endif
#if LV_USE_DRAW_VGLITE
lv_draw_vglite_deinit();
#endif
#if LV_USE_DRAW_SW
lv_draw_sw_deinit();
#endif
lv_draw_deinit();
_lv_group_deinit();
_lv_anim_core_deinit();
_lv_layout_deinit();
_lv_fs_deinit();
_lv_timer_core_deinit();
#if LV_USE_PROFILER && LV_USE_PROFILER_BUILTIN
lv_profiler_builtin_uninit();
#endif
#if LV_USE_OBJ_ID_BUILTIN
lv_objid_builtin_destroy();
#endif
lv_mem_deinit();
#if LV_USE_LOG
lv_log_register_print_cb(NULL);
#endif
#if LV_USE_OBJ_ID_BUILTIN
lv_objid_builtin_destroy();
#endif
#endif
lv_initialized = false;

View File

@@ -64,6 +64,11 @@ void _lv_anim_core_init(void)
state.anim_run_round = false;
}
void _lv_anim_core_deinit(void)
{
lv_anim_delete_all();
}
void lv_anim_init(lv_anim_t * a)
{
lv_memzero(a, sizeof(lv_anim_t));

View File

@@ -173,6 +173,11 @@ typedef struct _lv_anim_t {
*/
void _lv_anim_core_init(void);
/**
* Deinit. the animation module
*/
void _lv_anim_core_deinit(void);
/**
* Initialize an animation variable.
* E.g.:

View File

@@ -42,6 +42,11 @@ void _lv_cache_init(void)
lv_mutex_init(&_cache_manager.mutex);
}
void _lv_cache_deinit(void)
{
lv_mutex_delete(&_cache_manager.mutex);
}
void lv_cache_set_manager(lv_cache_manager_t * manager)
{
LV_ASSERT(_cache_manager.locked);

View File

@@ -152,6 +152,11 @@ typedef struct {
*/
void _lv_cache_init(void);
/**
* Deinitialize the cache module
*/
void _lv_cache_deinit(void);
/**
* Set new cache manager
* @param manager the new cache manager with callback functions set

View File

@@ -65,6 +65,11 @@ void _lv_cache_builtin_init(void)
_cache_manager.empty_cb = empty_cb;
}
void _lv_cache_builtin_deinit(void)
{
_lv_ll_clear(&dsc.entry_ll);
}
/**********************
* STATIC FUNCTIONS
**********************/

View File

@@ -34,6 +34,8 @@ typedef struct {
void _lv_cache_builtin_init(void);
void _lv_cache_builtin_deinit(void);
/**********************
* MACROS
**********************/

View File

@@ -45,6 +45,11 @@ void _lv_fs_init(void)
_lv_ll_init(fsdrv_ll_p, sizeof(lv_fs_drv_t *));
}
void _lv_fs_deinit(void)
{
_lv_ll_clear(fsdrv_ll_p);
}
bool lv_fs_is_ready(char letter)
{
lv_fs_drv_t * drv = lv_fs_get_drv(letter);

View File

@@ -133,6 +133,11 @@ typedef struct {
*/
void _lv_fs_init(void);
/**
* Deinitialize the File system interface
*/
void _lv_fs_deinit(void);
/**
* Initialize a file system driver with default values.
* It is used to ensure all fields have known values and not memory junk.

View File

@@ -242,6 +242,13 @@ void lv_timer_enable(bool en)
if(en) lv_timer_handler_resume();
}
void _lv_timer_core_deinit(void)
{
lv_timer_enable(false);
_lv_ll_clear(timer_ll_p);
}
uint8_t lv_timer_get_idle(void)
{
return state.idle_last;

View File

@@ -85,6 +85,11 @@ typedef struct {
*/
void _lv_timer_core_init(void);
/**
* Deinit the lv_timer module
*/
void _lv_timer_core_deinit(void);
//! @cond Doxygen_Suppress
/**