mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-11-28 02:45:45 +03:00
[FL-1320] Fix archive memleak (#565)
* iButton: fix timer initialization * Archive: fix strings memleak * Archive: optimize string handling * Archive: fix strings non-memleak
This commit is contained in:
parent
29da0e360c
commit
f153a745eb
@ -8,12 +8,12 @@ static bool is_favourite(ArchiveApp* archive, ArchiveFile_t* file) {
|
|||||||
FS_Error fr;
|
FS_Error fr;
|
||||||
string_t path;
|
string_t path;
|
||||||
|
|
||||||
string_init_set(path, "favourites/");
|
string_init_printf(path, "favourites/%s", string_get_cstr(file->name));
|
||||||
string_cat(path, file->name);
|
|
||||||
|
|
||||||
fr = common_api->info(string_get_cstr(path), &file_info, NULL, 0);
|
fr = common_api->info(string_get_cstr(path), &file_info, NULL, 0);
|
||||||
FURI_LOG_I("FAV", "%d", fr);
|
FURI_LOG_I("FAV", "%d", fr);
|
||||||
|
|
||||||
|
string_clear(path);
|
||||||
return fr == 0 || fr == 2;
|
return fr == 0 || fr == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,12 +241,12 @@ static void archive_add_to_favourites(ArchiveApp* archive) {
|
|||||||
string_t buffer_src;
|
string_t buffer_src;
|
||||||
string_t buffer_dst;
|
string_t buffer_dst;
|
||||||
|
|
||||||
string_init_set(buffer_src, archive->browser.path);
|
string_init_printf(
|
||||||
string_cat(buffer_src, "/");
|
buffer_src,
|
||||||
string_cat(buffer_src, archive->browser.name);
|
"%s/%s",
|
||||||
|
string_get_cstr(archive->browser.path),
|
||||||
string_init_set_str(buffer_dst, "/favourites/");
|
string_get_cstr(archive->browser.name));
|
||||||
string_cat(buffer_dst, archive->browser.name);
|
string_init_printf(buffer_dst, "/favourites/%s", string_get_cstr(archive->browser.name));
|
||||||
|
|
||||||
fr = file_api->open(&src, string_get_cstr(buffer_src), FSAM_READ, FSOM_OPEN_EXISTING);
|
fr = file_api->open(&src, string_get_cstr(buffer_src), FSAM_READ, FSOM_OPEN_EXISTING);
|
||||||
FURI_LOG_I("FATFS", "OPEN: %d", fr);
|
FURI_LOG_I("FATFS", "OPEN: %d", fr);
|
||||||
@ -276,14 +276,16 @@ static void archive_text_input_callback(void* context) {
|
|||||||
string_t buffer_src;
|
string_t buffer_src;
|
||||||
string_t buffer_dst;
|
string_t buffer_dst;
|
||||||
|
|
||||||
string_init_set(buffer_src, archive->browser.path);
|
string_init_printf(
|
||||||
string_init_set(buffer_dst, archive->browser.path);
|
buffer_src,
|
||||||
|
"%s/%s",
|
||||||
string_cat(buffer_src, "/");
|
string_get_cstr(archive->browser.path),
|
||||||
string_cat(buffer_dst, "/");
|
string_get_cstr(archive->browser.name));
|
||||||
|
string_init_printf(
|
||||||
string_cat(buffer_src, archive->browser.name);
|
buffer_dst,
|
||||||
string_cat_str(buffer_dst, archive->browser.text_input_buffer);
|
"%s/%s",
|
||||||
|
string_get_cstr(archive->browser.path),
|
||||||
|
archive->browser.text_input_buffer);
|
||||||
|
|
||||||
// append extension
|
// append extension
|
||||||
|
|
||||||
@ -312,9 +314,7 @@ static void archive_enter_text_input(ArchiveApp* archive) {
|
|||||||
*archive->browser.text_input_buffer = '\0';
|
*archive->browser.text_input_buffer = '\0';
|
||||||
|
|
||||||
strlcpy(
|
strlcpy(
|
||||||
archive->browser.text_input_buffer,
|
archive->browser.text_input_buffer, string_get_cstr(archive->browser.name), MAX_NAME_LEN);
|
||||||
string_get_cstr(archive->browser.name),
|
|
||||||
string_size(archive->browser.name));
|
|
||||||
|
|
||||||
archive_trim_file_ext(archive->browser.text_input_buffer);
|
archive_trim_file_ext(archive->browser.text_input_buffer);
|
||||||
|
|
||||||
@ -376,20 +376,17 @@ static void archive_delete_file(ArchiveApp* archive, ArchiveFile_t* file, bool f
|
|||||||
string_init(path);
|
string_init(path);
|
||||||
|
|
||||||
if(!fav && !orig) {
|
if(!fav && !orig) {
|
||||||
string_set(path, archive->browser.path);
|
string_printf(
|
||||||
string_cat(path, "/");
|
path, "%s/%s", string_get_cstr(archive->browser.path), string_get_cstr(file->name));
|
||||||
string_cat(path, file->name);
|
|
||||||
common_api->remove(string_get_cstr(path));
|
common_api->remove(string_get_cstr(path));
|
||||||
|
|
||||||
} else { // remove from favorites
|
} else { // remove from favorites
|
||||||
string_set(path, "favourites/");
|
string_printf(path, "favourites/%s", string_get_cstr(file->name));
|
||||||
string_cat(path, file->name);
|
|
||||||
common_api->remove(string_get_cstr(path));
|
common_api->remove(string_get_cstr(path));
|
||||||
|
|
||||||
if(orig) { // remove original file
|
if(orig) { // remove original file
|
||||||
string_set_str(path, get_default_path(file->type));
|
string_printf(
|
||||||
string_cat(path, "/");
|
path, "%s/%s", get_default_path(file->type), string_get_cstr(file->name));
|
||||||
string_cat(path, file->name);
|
|
||||||
common_api->remove(string_get_cstr(path));
|
common_api->remove(string_get_cstr(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,9 +420,11 @@ static void archive_file_menu_callback(ArchiveApp* archive) {
|
|||||||
case 0:
|
case 0:
|
||||||
if(is_known_app(selected->type)) {
|
if(is_known_app(selected->type)) {
|
||||||
string_t full_path;
|
string_t full_path;
|
||||||
string_init_set(full_path, archive->browser.path);
|
string_init_printf(
|
||||||
string_cat(full_path, "/");
|
full_path,
|
||||||
string_cat(full_path, selected->name);
|
"%s/%s",
|
||||||
|
string_get_cstr(archive->browser.path),
|
||||||
|
string_get_cstr(selected->name));
|
||||||
|
|
||||||
archive_open_app(
|
archive_open_app(
|
||||||
archive, flipper_app_name[selected->type], string_get_cstr(full_path));
|
archive, flipper_app_name[selected->type], string_get_cstr(full_path));
|
||||||
|
@ -16,11 +16,11 @@ void PulseSequencer::start() {
|
|||||||
callback_pointer = cbc::obtain_connector(this, &PulseSequencer::timer_elapsed_callback);
|
callback_pointer = cbc::obtain_connector(this, &PulseSequencer::timer_elapsed_callback);
|
||||||
api_interrupt_add(callback_pointer, InterruptTypeTimerUpdate, this);
|
api_interrupt_add(callback_pointer, InterruptTypeTimerUpdate, this);
|
||||||
|
|
||||||
|
period_index = 1;
|
||||||
init_timer(periods[period_index]);
|
init_timer(periods[period_index]);
|
||||||
pin_state = pin_start_state;
|
pin_state = pin_start_state;
|
||||||
hal_gpio_write(&ibutton_gpio, pin_state);
|
hal_gpio_write(&ibutton_gpio, pin_state);
|
||||||
pin_state = !pin_state;
|
pin_state = !pin_state;
|
||||||
period_index = 1;
|
|
||||||
|
|
||||||
HAL_TIM_Base_Start_IT(&htim1);
|
HAL_TIM_Base_Start_IT(&htim1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user