From 9fd73e9023561f8241ead03af89c513bb69ca3b8 Mon Sep 17 00:00:00 2001 From: TheSomeMan Date: Tue, 16 Apr 2024 22:24:01 +0700 Subject: [PATCH] Fix #287: wifi_manager_stop causes panic handler when it is called before wifi_manager_start (#288) * Fix #287: wifi_manager_stop causes panic handler when it is called before wifi_manager_start * [#287] Fix code smell found by SonarCloud --- src/wifi_manager.c | 4 ++++ src/wifi_manager_internal.c | 10 ++++++++++ src/wifi_manager_internal.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 459a5d0..e126c48 100644 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -274,6 +274,10 @@ wifi_manager_disable_wps(void) void wifi_manager_stop(void) { + if (!wifi_manager_is_initialized()) + { + return; + } if (!wifiman_msg_send_cmd_stop_and_destroy()) { LOG_ERR("%s failed", "wifiman_msg_send_cmd_stop_and_destroy"); diff --git a/src/wifi_manager_internal.c b/src/wifi_manager_internal.c index 6af51e4..227637b 100644 --- a/src/wifi_manager_internal.c +++ b/src/wifi_manager_internal.c @@ -50,6 +50,16 @@ static os_sema_static_t g_scan_sync_sema_mem; static os_mutex_recursive_t g_p_wifi_mutex; static os_mutex_recursive_static_t g_wifi_manager_mutex_mem; +bool +wifi_manager_is_initialized(void) +{ + if (NULL == g_p_wifi_mutex) + { + return false; + } + return true; +} + void wifi_manager_init_mutex(void) { diff --git a/src/wifi_manager_internal.h b/src/wifi_manager_internal.h index 7b39de1..a7c1f62 100644 --- a/src/wifi_manager_internal.h +++ b/src/wifi_manager_internal.h @@ -85,6 +85,9 @@ extern EventGroupHandle_t g_p_wifi_manager_event_group; extern esp_wps_config_t g_wps_config; extern bool g_wifi_wps_enabled; +bool +wifi_manager_is_initialized(void); + void wifi_manager_init_mutex(void);