Skip to content

Commit

Permalink
outbox: Cleanup all items when connection closes
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Jun 24, 2021
1 parent 2e15c9a commit 1a94efe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/include/mqtt_outbox.h
Expand Up @@ -58,6 +58,7 @@ esp_err_t outbox_set_tick(outbox_handle_t outbox, int msg_id, outbox_tick_t tick
int outbox_get_size(outbox_handle_t outbox);
esp_err_t outbox_cleanup(outbox_handle_t outbox, int max_size);
void outbox_destroy(outbox_handle_t outbox);
void outbox_delete_all_items(outbox_handle_t outbox);

#ifdef __cplusplus
}
Expand Down
6 changes: 5 additions & 1 deletion lib/mqtt_outbox.c
Expand Up @@ -224,14 +224,18 @@ esp_err_t outbox_cleanup(outbox_handle_t outbox, int max_size)
return ESP_OK;
}

void outbox_destroy(outbox_handle_t outbox)
void outbox_delete_all_items(outbox_handle_t outbox)
{
outbox_item_handle_t item, tmp;
STAILQ_FOREACH_SAFE(item, outbox, next, tmp) {
STAILQ_REMOVE(outbox, item, outbox_item, next);
free(item->buffer);
free(item);
}
}
void outbox_destroy(outbox_handle_t outbox)
{
outbox_delete_all_items(outbox);
free(outbox);
}

Expand Down
1 change: 1 addition & 0 deletions mqtt_client.c
Expand Up @@ -1494,6 +1494,7 @@ static void esp_mqtt_task(void *pv)

}
esp_transport_close(client->transport);
outbox_delete_all_items(client->outbox);
xEventGroupSetBits(client->status_bits, STOPPED_BIT);

vTaskDelete(NULL);
Expand Down

0 comments on commit 1a94efe

Please sign in to comment.