From a0a7bf5c107d31c087a75d82813622bfbaa34d4a Mon Sep 17 00:00:00 2001 From: Mike Szczys Date: Tue, 30 Jul 2024 13:52:25 -0500 Subject: [PATCH] coap: libcoap: stop client before destroy If the client is running when golioth_client_destroy() is called it needs to be stopped before freeing the client. When the client is stopped, golioth_sys_client_disconnected() is now called which in turn sets golioth_debug_set_cloud_log_enabled() to false. This prevents attempts to send log messages to Golioth when the client is not connected. Signed-off-by: Mike Szczys --- src/coap_client_libcoap.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coap_client_libcoap.c b/src/coap_client_libcoap.c index 897f0a179..dcc4658a8 100644 --- a/src/coap_client_libcoap.c +++ b/src/coap_client_libcoap.c @@ -1241,6 +1241,7 @@ static void golioth_coap_client_thread(void *arg) cleanup: GLTH_LOGI(TAG, "Ending session"); + golioth_sys_client_disconnected(client); if (client->event_callback && client->session_connected) { client->event_callback(client, @@ -1388,6 +1389,10 @@ void golioth_client_destroy(struct golioth_client *client) { return; } + if (client->is_running) + { + golioth_client_stop(client); + } if (client->keepalive_timer) { golioth_sys_timer_destroy(client->keepalive_timer);