From: mathieu.desnoyers@efficios.com (Mathieu Desnoyers)
Subject: [lttng-dev] [PATCH babeltrace] Fix: Double free in bt_context_remove_trace().
Date: Mon, 21 Jan 2013 14:32:25 -0500 [thread overview]
Message-ID: <20130121193225.GA8005@Krystal> (raw)
In-Reply-To: <1358777874-24083-1-git-send-email-jeremie.galarneau@efficios.com>
* J?r?mie Galarneau (jeremie.galarneau at efficios.com) wrote:
> ctf_close_trace was being called twice when calling bt_context_remove_trace thus
> causing free() to be called on an invalid pointer.
>
> Calling bt_context_remove_trace() would call ctf_close_trace() once via the
> close_handle callback registered on the ctf format struct and a second call would
> take place from bt_trace_handle_destroy() which is registered as the
> value_destroy_func on the trace_handles hash table of the current context.
>
> The first explicit call to handle->format->close_trace is unnecessary.
>
> The crash is reproducible by invoking the tests-python.py script.
I think we should leave the close_trace calls in both locations, but set
handle->td to -1 when we close it, and test for negative handle ID
before doing the close.
Thanks,
Mathieu
>
> Signed-off-by: J?r?mie Galarneau <jeremie.galarneau at efficios.com>
> ---
> lib/context.c | 8 +-------
> lib/trace-handle.c | 5 ++++-
> 2 files changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/lib/context.c b/lib/context.c
> index 5516e49..05fb994 100644
> --- a/lib/context.c
> +++ b/lib/context.c
> @@ -156,7 +156,6 @@ end:
> int bt_context_remove_trace(struct bt_context *ctx, int handle_id)
> {
> struct bt_trace_handle *handle;
> - int ret;
>
> if (!ctx)
> return -EINVAL;
> @@ -168,12 +167,7 @@ int bt_context_remove_trace(struct bt_context *ctx, int handle_id)
>
> /* Remove from containers */
> trace_collection_remove(ctx->tc, handle->td);
> - /* Close the trace */
> - ret = handle->format->close_trace(handle->td);
> - if (ret) {
> - fprintf(stderr, "Error in close_trace callback\n");
> - return ret;
> - }
> +
> /* Remove and free the handle */
> g_hash_table_remove(ctx->trace_handles,
> (gpointer) (unsigned long) handle_id);
> diff --git a/lib/trace-handle.c b/lib/trace-handle.c
> index 0da565b..17a6e0d 100644
> --- a/lib/trace-handle.c
> +++ b/lib/trace-handle.c
> @@ -49,7 +49,10 @@ 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);
> + if (th->format->close_trace(th->td)) {
> + fprintf(stderr, "Error in close_trace callback\n");
> + }
> +
> g_free(th);
> }
>
> --
> 1.8.1.1
>
>
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2013-01-21 19:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-21 14:17 Jérémie Galarneau
2013-01-21 19:32 ` Mathieu Desnoyers [this message]
2013-01-21 22:04 ` Julien Desfossez
2013-01-21 22:13 ` Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130121193225.GA8005@Krystal \
--to=mathieu.desnoyers@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox