1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

img_decoder: return on out of memory error

This commit is contained in:
Gabor Kiss-Vamosi 2020-03-08 03:36:03 +01:00
parent ad44495146
commit 8880326abd

View File

@ -336,18 +336,21 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder
/*If the file was open successfully save the file descriptor*/ /*If the file was open successfully save the file descriptor*/
if(dsc->user_data == NULL) { if(dsc->user_data == NULL) {
dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t)); dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
LV_ASSERT_MEM(dsc->user_data);
if(dsc->user_data == NULL) { if(dsc->user_data == NULL) {
LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
LV_ASSERT_MEM(dsc->user_data); return LV_RES_INV;
} }
memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t)); memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t));
} }
lv_img_decoder_built_in_data_t * user_data = dsc->user_data; lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
user_data->f = lv_mem_alloc(sizeof(f)); user_data->f = lv_mem_alloc(sizeof(f));
LV_ASSERT_MEM(user_data->f);
if(user_data->f == NULL) { if(user_data->f == NULL) {
LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
LV_ASSERT_MEM(user_data->f); lv_img_decoder_built_in_close(decoder, dsc);
return LV_RES_INV;
} }
memcpy(user_data->f, &f, sizeof(f)); memcpy(user_data->f, &f, sizeof(f));
@ -390,21 +393,24 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder
/*Allocate the palette*/ /*Allocate the palette*/
if(dsc->user_data == NULL) { if(dsc->user_data == NULL) {
dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t)); dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t));
LV_ASSERT_MEM(dsc->user_data);
if(dsc->user_data == NULL) { if(dsc->user_data == NULL) {
LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
LV_ASSERT_MEM(dsc->user_data); lv_img_decoder_built_in_close(decoder, dsc);
return LV_RES_INV;
} }
memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t)); memset(dsc->user_data, 0, sizeof(lv_img_decoder_built_in_data_t));
} }
lv_img_decoder_built_in_data_t * user_data = dsc->user_data; lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
user_data->palette = lv_mem_alloc(palette_size * sizeof(lv_color_t)); user_data->palette = lv_mem_alloc(palette_size * sizeof(lv_color_t));
LV_ASSERT_MEM(user_data->palette);
user_data->opa = lv_mem_alloc(palette_size * sizeof(lv_opa_t)); user_data->opa = lv_mem_alloc(palette_size * sizeof(lv_opa_t));
LV_ASSERT_MEM(user_data->opa);
if(user_data->palette == NULL || user_data->opa == NULL) { if(user_data->palette == NULL || user_data->opa == NULL) {
LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
#if LV_USE_FILESYSTEM lv_img_decoder_built_in_close(decoder, dsc);
LV_ASSERT_MEM(user_data->f); return LV_RES_INV;
#endif
} }
if(dsc->src_type == LV_IMG_SRC_FILE) { if(dsc->src_type == LV_IMG_SRC_FILE) {