+ struct bt_trace_handle *handle;
+
+ handle = g_hash_table_lookup(ctx->trace_handles,
+ (gpointer) (unsigned long) handle_id);
+ assert(handle != NULL);
+
+ /* Remove from containers */
+ trace_collection_remove(ctx->tc, handle->td);
+ g_hash_table_remove(ctx->trace_handles,
+ (gpointer) (unsigned long) handle_id);
+
+ /* Close the trace */
+ handle->format->close_trace(handle->td);
+
+ /* Destory the handle */
+ bt_trace_handle_destroy(handle);
+}
+
+static
+void bt_context_destroy(struct bt_context *ctx)
+{
+ finalize_trace_collection(ctx->tc);
+
+ /* Remote all traces. The g_hash_table_destroy will call
+ * bt_trace_handle_destroy on each elements.
+ */
+ g_hash_table_destroy(ctx->trace_handles);
+
+ /* ctx->tc should always be valid */
+ assert(ctx->tc != NULL);
+ g_free(ctx->tc);
+ g_free(ctx);