mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Archive: Fix memory leak with Search+Info --nobuild
This commit is contained in:
@@ -70,10 +70,15 @@ void archive_free(ArchiveApp* archive) {
|
||||
|
||||
scene_manager_set_scene_state(archive->scene_manager, ArchiveAppSceneInfo, false);
|
||||
scene_manager_set_scene_state(archive->scene_manager, ArchiveAppSceneSearch, false);
|
||||
if(archive->thread) {
|
||||
furi_thread_join(archive->thread);
|
||||
furi_thread_free(archive->thread);
|
||||
archive->thread = NULL;
|
||||
if(archive->info_thread) {
|
||||
furi_thread_join(archive->info_thread);
|
||||
furi_thread_free(archive->info_thread);
|
||||
archive->info_thread = NULL;
|
||||
}
|
||||
if(archive->search_thread) {
|
||||
furi_thread_join(archive->search_thread);
|
||||
furi_thread_free(archive->search_thread);
|
||||
archive->search_thread = NULL;
|
||||
}
|
||||
|
||||
if(archive->browser->disk_image) {
|
||||
|
||||
@@ -45,7 +45,8 @@ struct ArchiveApp {
|
||||
|
||||
WidgetElement* size_element;
|
||||
WidgetElement* count_element;
|
||||
FuriThread* thread;
|
||||
FuriThread* info_thread;
|
||||
FuriThread* search_thread;
|
||||
};
|
||||
|
||||
void archive_show_loading_popup(ArchiveApp* context, bool show);
|
||||
|
||||
@@ -534,10 +534,10 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
||||
with_view_model(
|
||||
browser->view, ArchiveBrowserViewModel * model, { archive = model->archive; }, false);
|
||||
scene_manager_set_scene_state(archive->scene_manager, ArchiveAppSceneSearch, false);
|
||||
if(archive->thread) {
|
||||
furi_thread_join(archive->thread);
|
||||
furi_thread_free(archive->thread);
|
||||
archive->thread = NULL;
|
||||
if(archive->search_thread) {
|
||||
furi_thread_join(archive->search_thread);
|
||||
furi_thread_free(archive->search_thread);
|
||||
archive->search_thread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -425,10 +425,10 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
bool open =
|
||||
!scene_manager_get_scene_state(archive->scene_manager, ArchiveAppSceneSearch);
|
||||
scene_manager_set_scene_state(archive->scene_manager, ArchiveAppSceneSearch, false);
|
||||
if(archive->thread) {
|
||||
furi_thread_join(archive->thread);
|
||||
furi_thread_free(archive->thread);
|
||||
archive->thread = NULL;
|
||||
if(archive->search_thread) {
|
||||
furi_thread_join(archive->search_thread);
|
||||
furi_thread_free(archive->search_thread);
|
||||
archive->search_thread = NULL;
|
||||
}
|
||||
if(open) scene_manager_next_scene(archive->scene_manager, ArchiveAppSceneSearch);
|
||||
consumed = true;
|
||||
|
||||
@@ -216,12 +216,12 @@ void archive_scene_info_on_enter(void* context) {
|
||||
view_dispatcher_switch_to_view(instance->view_dispatcher, ArchiveViewWidget);
|
||||
|
||||
scene_manager_set_scene_state(instance->scene_manager, ArchiveAppSceneInfo, true);
|
||||
instance->thread = furi_thread_alloc_ex(
|
||||
instance->info_thread = furi_thread_alloc_ex(
|
||||
"ArchiveInfoWorker",
|
||||
1024,
|
||||
(FuriThreadCallback)(is_dir ? archive_scene_info_dirwalk : archive_scene_info_md5sum),
|
||||
instance);
|
||||
furi_thread_start(instance->thread);
|
||||
furi_thread_start(instance->info_thread);
|
||||
}
|
||||
|
||||
bool archive_scene_info_on_event(void* context, SceneManagerEvent event) {
|
||||
@@ -240,10 +240,10 @@ void archive_scene_info_on_exit(void* context) {
|
||||
ArchiveApp* app = (ArchiveApp*)context;
|
||||
|
||||
scene_manager_set_scene_state(app->scene_manager, ArchiveAppSceneInfo, false);
|
||||
if(app->thread) {
|
||||
furi_thread_join(app->thread);
|
||||
furi_thread_free(app->thread);
|
||||
app->thread = NULL;
|
||||
if(app->info_thread) {
|
||||
furi_thread_join(app->info_thread);
|
||||
furi_thread_free(app->info_thread);
|
||||
app->info_thread = NULL;
|
||||
}
|
||||
widget_reset(app->widget);
|
||||
}
|
||||
|
||||
@@ -98,15 +98,13 @@ bool archive_scene_search_on_event(void* context, SceneManagerEvent event) {
|
||||
archive_add_app_item(archive->browser, "/app:search/Cancel search");
|
||||
archive_set_item_count(archive->browser, 1);
|
||||
|
||||
// Thread here is fine because only the info pane uses it too,
|
||||
// but only for directories, which are ignored for search
|
||||
scene_manager_set_scene_state(archive->scene_manager, ArchiveAppSceneSearch, true);
|
||||
archive->thread = furi_thread_alloc_ex(
|
||||
"ArchiveSearchDirWalk",
|
||||
archive->search_thread = furi_thread_alloc_ex(
|
||||
"ArchiveSearchWorker",
|
||||
1024,
|
||||
(FuriThreadCallback)archive_scene_search_dirwalk,
|
||||
archive);
|
||||
furi_thread_start(archive->thread);
|
||||
furi_thread_start(archive->search_thread);
|
||||
|
||||
scene_manager_previous_scene(archive->scene_manager);
|
||||
consumed = true;
|
||||
|
||||
Reference in New Issue
Block a user