Skip to content

Commit

Permalink
coap: libcoap: stop client before destroy
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
szczys committed Jul 30, 2024
1 parent b2f0e31 commit a0a7bf5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/coap_client_libcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a0a7bf5

Please sign in to comment.