From a884b7fced951d8f0f2076a1b657d9633f00a4d6 Mon Sep 17 00:00:00 2001 From: Leeroy <135471162+LeeroysHub@users.noreply.github.com> Date: Sat, 26 Sep 2026 15:14:42 +1000 Subject: [PATCH] Free API resolvers after plugin loads, not on plugin unload * This allows us to remove a few plugin_resolver pointers from the ProtoPirateApp struct too. * The resolvers were never used, and arent required to unload or run the plugin. * No change to app, but this frees a bit more RAM --- helpers/protopirate_protocol_plugin_host.c | 16 ++++------------ helpers/protopirate_psa_bf_host.c | 9 ++------- helpers/protopirate_radio.c | 3 +-- helpers/protopirate_tool_scene_host.c | 7 +------ protopirate_app.c | 9 ++------- protopirate_app_i.h | 4 ---- scenes/protopirate_scene_emulate.c | 9 ++------- 7 files changed, 12 insertions(+), 45 deletions(-) diff --git a/helpers/protopirate_protocol_plugin_host.c b/helpers/protopirate_protocol_plugin_host.c index d5b2bd3..a2539bb 100644 --- a/helpers/protopirate_protocol_plugin_host.c +++ b/helpers/protopirate_protocol_plugin_host.c @@ -66,11 +66,6 @@ void protopirate_unload_protocol_plugin(ProtoPirateTxRx* txrx) { plugin_manager_free(txrx->protocol_plugin_manager); txrx->protocol_plugin_manager = NULL; } - - if(txrx->plugin_resolver) { - composite_api_resolver_free(txrx->plugin_resolver); - txrx->plugin_resolver = NULL; - } } static bool protopirate_ensure_protocol_registry_plugin( @@ -95,8 +90,7 @@ static bool protopirate_ensure_protocol_registry_plugin( return true; } - if(app->txrx->protocol_plugin || app->txrx->protocol_plugin_manager || - app->txrx->plugin_resolver) { + if(app->txrx->protocol_plugin || app->txrx->protocol_plugin_manager) { protopirate_unload_protocol_plugin(app->txrx); } @@ -154,11 +148,10 @@ static bool protopirate_ensure_protocol_registry_plugin( plugin->release(); } plugin_manager_free(manager); - composite_api_resolver_free(resolver); return false; } - app->txrx->plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->txrx->protocol_plugin_manager = manager; app->txrx->protocol_plugin = plugin; app->txrx->protocol_registry_route = route; @@ -205,8 +198,7 @@ static bool protopirate_ensure_tx_protocol_plugin( return true; } - if(app->txrx->protocol_plugin || app->txrx->protocol_plugin_manager || - app->txrx->plugin_resolver) { + if(app->txrx->protocol_plugin || app->txrx->protocol_plugin_manager) { protopirate_unload_protocol_plugin(app->txrx); } @@ -260,7 +252,7 @@ static bool protopirate_ensure_tx_protocol_plugin( return false; } - app->txrx->plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->txrx->protocol_plugin_manager = manager; app->txrx->protocol_plugin = plugin; *registry = plugin->registry; diff --git a/helpers/protopirate_psa_bf_host.c b/helpers/protopirate_psa_bf_host.c index 0052549..b34342b 100644 --- a/helpers/protopirate_psa_bf_host.c +++ b/helpers/protopirate_psa_bf_host.c @@ -124,11 +124,6 @@ static void psa_bf_plugin_unload(ProtoPirateApp* app) { plugin_manager_free(app->psa_bf_plugin_manager); app->psa_bf_plugin_manager = NULL; } - - if(app->psa_bf_plugin_resolver) { - composite_api_resolver_free(app->psa_bf_plugin_resolver); - app->psa_bf_plugin_resolver = NULL; - } } bool protopirate_psa_bf_plugin_ensure_loaded(ProtoPirateApp* app) { @@ -136,7 +131,7 @@ bool protopirate_psa_bf_plugin_ensure_loaded(ProtoPirateApp* app) { if(app->psa_bf_plugin) return true; - if(app->psa_bf_plugin_manager || app->psa_bf_plugin_resolver) { + if(app->psa_bf_plugin_manager) { psa_bf_plugin_unload(app); } @@ -173,7 +168,7 @@ bool protopirate_psa_bf_plugin_ensure_loaded(ProtoPirateApp* app) { return false; } - app->psa_bf_plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->psa_bf_plugin_manager = manager; app->psa_bf_plugin = plugin; plugin->set_host_api(&protopirate_psa_bf_host_api); diff --git a/helpers/protopirate_radio.c b/helpers/protopirate_radio.c index d83e082..37fd461 100644 --- a/helpers/protopirate_radio.c +++ b/helpers/protopirate_radio.c @@ -203,8 +203,7 @@ void protopirate_radio_deinit(ProtoPirateApp* app) { bool has_radio_resources = app->radio_initialized || app->txrx->worker || app->txrx->environment || app->txrx->receiver || app->txrx->history || app->txrx->radio_device || - app->txrx->protocol_plugin_manager || app->txrx->plugin_resolver || - app->txrx->protocol_plugin; + app->txrx->protocol_plugin_manager || app->txrx->protocol_plugin; if(!has_radio_resources) { #ifndef REMOVE_LOGS FURI_LOG_D(TAG, "Radio resources were not initialized, returning"); diff --git a/helpers/protopirate_tool_scene_host.c b/helpers/protopirate_tool_scene_host.c index 44f9064..47d3826 100644 --- a/helpers/protopirate_tool_scene_host.c +++ b/helpers/protopirate_tool_scene_host.c @@ -140,11 +140,6 @@ static void protopirate_tool_scene_plugin_unload(ProtoPirateApp* app) { plugin_manager_free(app->tool_scene_plugin_manager); app->tool_scene_plugin_manager = NULL; } - - if(app->tool_scene_plugin_resolver) { - composite_api_resolver_free(app->tool_scene_plugin_resolver); - app->tool_scene_plugin_resolver = NULL; - } } static bool protopirate_tool_scene_plugin_ensure_loaded( @@ -203,7 +198,7 @@ static bool protopirate_tool_scene_plugin_ensure_loaded( return false; } - app->tool_scene_plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->tool_scene_plugin_manager = manager; app->tool_scene_plugin = plugin; app->tool_scene_plugin_kind = kind; diff --git a/protopirate_app.c b/protopirate_app.c index d1bce56..355c46f 100644 --- a/protopirate_app.c +++ b/protopirate_app.c @@ -30,11 +30,6 @@ void shared_plugin_unload(ProtoPirateApp* app, ProtoPirateSharedPlugin plugin_ty plugin_manager_free(app->plugin_manager); app->plugin_manager = NULL; } - - if(app->plugin_resolver) { - composite_api_resolver_free(app->plugin_resolver); - app->plugin_resolver = NULL; - } } bool shared_plugin_load(ProtoPirateApp* app, ProtoPirateSharedPlugin plugin_type) { @@ -48,7 +43,7 @@ bool shared_plugin_load(ProtoPirateApp* app, ProtoPirateSharedPlugin plugin_type if(app->about_plugin) return true; } - if(app->plugin_manager || app->plugin_resolver) { + if(app->plugin_manager) { shared_plugin_unload(app, plugin_type); } @@ -122,7 +117,7 @@ bool shared_plugin_load(ProtoPirateApp* app, ProtoPirateSharedPlugin plugin_type app->about_plugin = plugin_about; } - app->plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->plugin_manager = manager; return true; } diff --git a/protopirate_app_i.h b/protopirate_app_i.h index 54100a5..b51668c 100644 --- a/protopirate_app_i.h +++ b/protopirate_app_i.h @@ -59,7 +59,6 @@ typedef struct ProtoPirateTxRx { SubGhzReceiver* receiver; SubGhzRadioPreset* preset; const SubGhzProtocolRegistry* protocol_registry; - CompositeApiResolver* plugin_resolver; PluginManager* protocol_plugin_manager; const ProtoPirateProtocolPlugin* protocol_plugin; ProtoPirateProtocolRegistryRoute protocol_registry_route; @@ -105,7 +104,6 @@ struct ProtoPirateApp { char save_filename[64]; FuriString* save_protocol; uint16_t save_history_idx; - CompositeApiResolver* plugin_resolver; PluginManager* plugin_manager; #ifdef ENABLE_EMULATE_FEATURE #define EMULATE_NAV_NONE 0U @@ -117,10 +115,8 @@ struct ProtoPirateApp { const ProtoPirateConfigPlugin* config_plugin; const ProtoPirateSavedInfoPlugin* saved_info_plugin; const ProtoPirateAboutPlugin* about_plugin; - CompositeApiResolver* psa_bf_plugin_resolver; PluginManager* psa_bf_plugin_manager; const ProtoPiratePsaBfPlugin* psa_bf_plugin; - CompositeApiResolver* tool_scene_plugin_resolver; PluginManager* tool_scene_plugin_manager; const ProtoPirateToolScenePlugin* tool_scene_plugin; ProtoPirateToolScenePluginKind tool_scene_plugin_kind; diff --git a/scenes/protopirate_scene_emulate.c b/scenes/protopirate_scene_emulate.c index 6493e98..c8cd97a 100644 --- a/scenes/protopirate_scene_emulate.c +++ b/scenes/protopirate_scene_emulate.c @@ -98,11 +98,6 @@ static void emulate_plugin_unload(ProtoPirateApp* app) { plugin_manager_free(app->plugin_manager); app->plugin_manager = NULL; } - - if(app->plugin_resolver) { - composite_api_resolver_free(app->plugin_resolver); - app->plugin_resolver = NULL; - } } static bool emulate_plugin_load(ProtoPirateApp* app) { @@ -110,7 +105,7 @@ static bool emulate_plugin_load(ProtoPirateApp* app) { if(app->emulate_plugin) return true; - if(app->plugin_manager || app->plugin_resolver) { + if(app->plugin_manager) { emulate_plugin_unload(app); } @@ -148,7 +143,7 @@ static bool emulate_plugin_load(ProtoPirateApp* app) { return false; } - app->plugin_resolver = resolver; + composite_api_resolver_free(resolver); app->plugin_manager = manager; app->emulate_plugin = plugin;