From e6d85e38ecef913abbb661e80ca91478bdd0113f Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Tue, 16 Oct 2012 14:23:12 -0400 Subject: [PATCH] Fix : cleanup teardown of context Fix the error path when a trace is opened but errors occur when we index it, and close all traces when the context is destroyed. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- lib/context.c | 12 ++++++++---- lib/trace-handle.c | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/context.c b/lib/context.c index 0f727a18..5c9f4b06 100644 --- a/lib/context.c +++ b/lib/context.c @@ -103,7 +103,7 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, fprintf(stderr, "[error] [Context] Creating trace handle %s .\n\n", path); ret = -1; - goto end; + goto error; } handle->format = fmt; handle->td = td; @@ -123,11 +123,11 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, handle); ret = trace_collection_add(ctx->tc, td); if (ret != 0) - goto end; + goto error; ret = fmt->convert_index_timestamp(td); if (ret < 0) - goto end; + goto error; handle->real_timestamp_begin = fmt->timestamp_begin(td, handle, BT_CLOCK_REAL); handle->real_timestamp_end = fmt->timestamp_end(td, handle, BT_CLOCK_REAL); @@ -135,6 +135,9 @@ int bt_context_add_trace(struct bt_context *ctx, const char *path, handle->cycles_timestamp_end = fmt->timestamp_end(td, handle, BT_CLOCK_CYCLES); return handle->id; + +error: + fmt->close_trace(td); end: return ret; } @@ -168,7 +171,8 @@ void bt_context_destroy(struct bt_context *ctx) assert(ctx); finalize_trace_collection(ctx->tc); - /* Remote all traces. The g_hash_table_destroy will call + /* + * Remove all traces. The g_hash_table_destroy will call * bt_trace_handle_destroy on each elements. */ g_hash_table_destroy(ctx->trace_handles); diff --git a/lib/trace-handle.c b/lib/trace-handle.c index f981adda..9cb654ad 100644 --- a/lib/trace-handle.c +++ b/lib/trace-handle.c @@ -41,6 +41,7 @@ struct bt_trace_handle *bt_trace_handle_create(struct bt_context *ctx) void bt_trace_handle_destroy(struct bt_trace_handle *th) { + th->format->close_trace(th->td); g_free(th); } -- 2.34.1