in source/client.c [663:727]
static void s_mqtt_client_connection_destroy_final(struct aws_mqtt_client_connection *connection) {
AWS_PRECONDITION(!connection || connection->allocator);
if (!connection) {
return;
}
/* If the slot is not NULL, the connection is still connected, which should be prevented from calling this function
*/
AWS_ASSERT(!connection->slot);
AWS_LOGF_DEBUG(AWS_LS_MQTT_CLIENT, "id=%p: Destroying connection", (void *)connection);
/* If the reconnect_task isn't freed, free it */
if (connection->reconnect_task) {
aws_mem_release(connection->reconnect_task->allocator, connection->reconnect_task);
}
aws_string_destroy(connection->host_name);
/* Clear the credentials */
if (connection->username) {
aws_string_destroy_secure(connection->username);
}
if (connection->password) {
aws_string_destroy_secure(connection->password);
}
/* Clean up the will */
aws_byte_buf_clean_up(&connection->will.topic);
aws_byte_buf_clean_up(&connection->will.payload);
/* Clear the client_id */
aws_byte_buf_clean_up(&connection->client_id);
/* Free all of the active subscriptions */
aws_mqtt_topic_tree_clean_up(&connection->thread_data.subscriptions);
aws_hash_table_clean_up(&connection->synced_data.outstanding_requests_table);
/* clean up the pending_requests if it's not empty */
while (!aws_linked_list_empty(&connection->synced_data.pending_requests_list)) {
struct aws_linked_list_node *node = aws_linked_list_pop_front(&connection->synced_data.pending_requests_list);
struct aws_mqtt_request *request = AWS_CONTAINER_OF(node, struct aws_mqtt_request, list_node);
/* Fire the callback and clean up the memory, as the connection get destroyed. */
if (request->on_complete) {
request->on_complete(
connection, request->packet_id, AWS_ERROR_MQTT_CONNECTION_DESTROYED, request->on_complete_ud);
}
aws_memory_pool_release(&connection->synced_data.requests_pool, request);
}
aws_memory_pool_clean_up(&connection->synced_data.requests_pool);
aws_mutex_clean_up(&connection->synced_data.lock);
aws_tls_connection_options_clean_up(&connection->tls_options);
/* Clean up the websocket proxy options */
if (connection->http_proxy_config) {
aws_http_proxy_config_destroy(connection->http_proxy_config);
connection->http_proxy_config = NULL;
}
aws_mqtt_client_release(connection->client);
/* Frees all allocated memory */
aws_mem_release(connection->allocator, connection);
}