mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 16:38:36 -07:00
Fix garbage memory freeing
This commit is contained in:
@@ -291,10 +291,9 @@ static void animation_storage_free_frames(BubbleAnimation* animation) {
|
|||||||
|
|
||||||
const Icon* icon = &animation->icon_animation;
|
const Icon* icon = &animation->icon_animation;
|
||||||
for(int i = 0; i < icon->frame_count; ++i) {
|
for(int i = 0; i < icon->frame_count; ++i) {
|
||||||
if(!icon->frames[i]) {
|
if(icon->frames[i]) {
|
||||||
break;
|
free((void*)icon->frames[i]);
|
||||||
}
|
}
|
||||||
free((void*)icon->frames[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free((void*)icon->frames);
|
free((void*)icon->frames);
|
||||||
@@ -326,7 +325,7 @@ static bool animation_storage_load_frames(
|
|||||||
FURI_CONST_ASSIGN(icon->width, width);
|
FURI_CONST_ASSIGN(icon->width, width);
|
||||||
icon->frames = malloc(sizeof(const uint8_t*) * icon->frame_count);
|
icon->frames = malloc(sizeof(const uint8_t*) * icon->frame_count);
|
||||||
|
|
||||||
bool frames_ok = false;
|
bool frames_ok = true;
|
||||||
File* file = storage_file_alloc(storage);
|
File* file = storage_file_alloc(storage);
|
||||||
FileInfo file_info;
|
FileInfo file_info;
|
||||||
FuriString* filename;
|
FuriString* filename;
|
||||||
@@ -334,35 +333,39 @@ static bool animation_storage_load_frames(
|
|||||||
size_t max_filesize = ROUND_UP_TO(width, 8) * height + 2;
|
size_t max_filesize = ROUND_UP_TO(width, 8) * height + 2;
|
||||||
|
|
||||||
for(int i = 0; i < icon->frame_count; ++i) {
|
for(int i = 0; i < icon->frame_count; ++i) {
|
||||||
frames_ok = false;
|
|
||||||
furi_string_printf(filename, "%s/%s/frame_%d.bm", ANIMATION_DIR, name, i);
|
|
||||||
|
|
||||||
FURI_CONST_ASSIGN_PTR(icon->frames[i], 0);
|
FURI_CONST_ASSIGN_PTR(icon->frames[i], 0);
|
||||||
if(storage_common_stat(storage, furi_string_get_cstr(filename), &file_info) != FSE_OK)
|
if(frames_ok) {
|
||||||
break;
|
frames_ok = false;
|
||||||
if(file_info.size > max_filesize) {
|
furi_string_printf(filename, "%s/%s/frame_%d.bm", ANIMATION_DIR, name, i);
|
||||||
FURI_LOG_E(
|
do {
|
||||||
TAG,
|
if(storage_common_stat(storage, furi_string_get_cstr(filename), &file_info) != FSE_OK)
|
||||||
"Filesize %lld, max: %d (width %d, height %d)",
|
break;
|
||||||
file_info.size,
|
if(file_info.size > max_filesize) {
|
||||||
max_filesize,
|
FURI_LOG_E(
|
||||||
width,
|
TAG,
|
||||||
height);
|
"Filesize %lld, max: %d (width %d, height %d)",
|
||||||
break;
|
file_info.size,
|
||||||
}
|
max_filesize,
|
||||||
if(!storage_file_open(
|
width,
|
||||||
file, furi_string_get_cstr(filename), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
height);
|
||||||
FURI_LOG_E(TAG, "Can't open file \'%s\'", furi_string_get_cstr(filename));
|
break;
|
||||||
break;
|
}
|
||||||
}
|
if(!storage_file_open(
|
||||||
|
file, furi_string_get_cstr(filename), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||||
|
FURI_LOG_E(TAG, "Can't open file \'%s\'", furi_string_get_cstr(filename));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(file_info.size));
|
FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(file_info.size));
|
||||||
if(storage_file_read(file, (void*)icon->frames[i], file_info.size) != file_info.size) {
|
if(storage_file_read(file, (void*)icon->frames[i], file_info.size) != file_info.size) {
|
||||||
FURI_LOG_E(TAG, "Read failed: \'%s\'", furi_string_get_cstr(filename));
|
FURI_LOG_E(TAG, "Read failed: \'%s\'", furi_string_get_cstr(filename));
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
frames_ok = true;
|
||||||
|
}
|
||||||
|
storage_file_close(file);
|
||||||
|
} while(0);
|
||||||
}
|
}
|
||||||
storage_file_close(file);
|
|
||||||
frames_ok = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!frames_ok) {
|
if(!frames_ok) {
|
||||||
|
|||||||
@@ -28,15 +28,20 @@ void anim(const Icon** replace, const char* name, FuriString* path, File* file)
|
|||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
for(int i = 0; ok && i < icon->frame_count; ++i) {
|
for(int i = 0; ok && i < icon->frame_count; ++i) {
|
||||||
ok = false;
|
FURI_CONST_ASSIGN_PTR(icon->frames[i], 0);
|
||||||
furi_string_printf(path, ICONS_FMT "/frame_%02d.bm", pack, name, i);
|
if(ok) {
|
||||||
if(!storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING))
|
ok = false;
|
||||||
break;
|
furi_string_printf(path, ICONS_FMT "/frame_%02d.bm", pack, name, i);
|
||||||
|
do {
|
||||||
|
if(!storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING))
|
||||||
|
break;
|
||||||
|
|
||||||
uint64_t size = storage_file_size(file);
|
uint64_t size = storage_file_size(file);
|
||||||
FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(size));
|
FURI_CONST_ASSIGN_PTR(icon->frames[i], malloc(size));
|
||||||
if(storage_file_read(file, (void*)icon->frames[i], size) == size) ok = true;
|
if(storage_file_read(file, (void*)icon->frames[i], size) == size) ok = true;
|
||||||
storage_file_close(file);
|
storage_file_close(file);
|
||||||
|
} while(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!ok) {
|
if(!ok) {
|
||||||
for(int i = 0; i < icon->frame_count; ++i) {
|
for(int i = 0; i < icon->frame_count; ++i) {
|
||||||
|
|||||||
Reference in New Issue
Block a user