Free font allocations on file open error

This commit is contained in:
fvanroie 2021-11-22 11:19:33 +01:00
parent cfcaa16ab3
commit e8f1300193

View File

@ -102,19 +102,19 @@ lv_font_t* hasp_font_load(const char* font_name)
if(res == LV_FS_RES_OK) { if(res == LV_FS_RES_OK) {
success = lvgl_load_font(&file, font); success = lvgl_load_font(&file, font);
}
if(!success) { lv_fs_close(&file);
LOG_WARNING(TAG_FONT, "Error loading font file: %s\n", font_name);
/*
* When `lvgl_load_font` fails it can leak some pointers.
* All non-null pointers can be assumed as allocated and
* `lv_font_free` should free them correctly.
*/
hasp_font_free(font);
font = NULL;
}
lv_fs_close(&file); if(!success) {
LOG_WARNING(TAG_FONT, "Error loading font %s", font_name);
/*
* When `lvgl_load_font` fails it can leak some pointers.
* All non-null pointers can be assumed as allocated and
* `lv_font_free` should free them correctly.
*/
hasp_font_free(font);
font = NULL;
} }
return font; return font;