From 29d9d76c476cbf3fdf6fa709bfbdc24309974f06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 28 Jan 2015 16:52:28 -0500 Subject: [PATCH] Fix: lock stream class after assigning stream id MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes a bug that was introduced by 2f100782 which made it possible to set custom stream class IDs. The stream class is frozen when a stream of its type is instanciated. However, the trace or writer must still assign a unique ID to the stream class if none were set prior. This modification moves the stream class locking (freeze) after the ID assignment check. Reported-by: Jiri Olsa Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/stream.c | 1 - formats/ctf/ir/trace.c | 1 + include/babeltrace/ctf-ir/stream-internal.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index d291981e..6a71466c 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -296,7 +296,6 @@ struct bt_ctf_stream *bt_ctf_stream_create( stream->id = stream_class->next_stream_id++; stream->stream_class = stream_class; bt_ctf_stream_class_get(stream_class); - bt_ctf_stream_class_freeze(stream_class); stream->events = g_ptr_array_new_with_free_func( (GDestroyNotify) bt_ctf_event_put); if (!stream->events) { diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 68bfd67a..59f696eb 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -185,6 +185,7 @@ struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace, bt_ctf_stream_get(stream); g_ptr_array_add(trace->streams, stream); + bt_ctf_stream_class_freeze(stream_class); trace->frozen = 1; return stream; diff --git a/include/babeltrace/ctf-ir/stream-internal.h b/include/babeltrace/ctf-ir/stream-internal.h index 4b3250b0..db5eeaf6 100644 --- a/include/babeltrace/ctf-ir/stream-internal.h +++ b/include/babeltrace/ctf-ir/stream-internal.h @@ -53,6 +53,7 @@ struct bt_ctf_stream { struct bt_ctf_field *event_context; }; +/* Stream class should be locked by the caller after creating a stream */ BT_HIDDEN struct bt_ctf_stream *bt_ctf_stream_create( struct bt_ctf_stream_class *stream_class, -- 2.34.1