Fix: bt_ctf_trace_freeze must fail if type resolving fails
[babeltrace.git] / formats / ctf / ir / trace.c
index 0943e8f97c123aed0c1315ce5a9d579415d6ca16..32de5bb5f0d74929faffe4c68b05e0cabe84ec40 100644 (file)
@@ -33,6 +33,7 @@
 #include <babeltrace/ctf-writer/functor-internal.h>
 #include <babeltrace/ctf-ir/event-types-internal.h>
 #include <babeltrace/ctf-ir/attributes-internal.h>
+#include <babeltrace/ctf-ir/visitor-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/objects.h>
@@ -45,7 +46,7 @@ void bt_ctf_trace_destroy(struct bt_ctf_ref *ref);
 static
 int init_trace_packet_header(struct bt_ctf_trace *trace);
 static
-void bt_ctf_trace_freeze(struct bt_ctf_trace *trace);
+int bt_ctf_trace_freeze(struct bt_ctf_trace *trace);
 
 static
 const unsigned int field_type_aliases_alignments[] = {
@@ -449,6 +450,11 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                }
        }
 
+       ret = bt_ctf_stream_class_resolve_types(stream_class, trace);
+       if (ret) {
+               goto end;
+       }
+
        stream_id = bt_ctf_stream_class_get_id(stream_class);
        if (stream_id < 0) {
                stream_id = trace->next_stream_id++;
@@ -463,7 +469,8 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
                        }
                }
 
-               if (bt_ctf_stream_class_set_id_no_check(stream_class, stream_id)) {
+               if (bt_ctf_stream_class_set_id_no_check(stream_class,
+                       stream_id)) {
                        /* TODO Should retry with a different stream id */
                        ret = -1;
                        goto end;
@@ -496,7 +503,10 @@ int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
        }
 
        bt_ctf_stream_class_freeze(stream_class);
-       bt_ctf_trace_freeze(trace);
+       if (!trace->frozen) {
+               ret = bt_ctf_trace_freeze(trace);
+               goto end;
+       }
 end:
        if (ret) {
                (void) bt_ctf_stream_class_set_trace(stream_class, NULL);
@@ -883,10 +893,19 @@ struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
 }
 
 static
-void bt_ctf_trace_freeze(struct bt_ctf_trace *trace)
+int bt_ctf_trace_freeze(struct bt_ctf_trace *trace)
 {
+       int ret = 0;
+
+       ret = bt_ctf_trace_resolve_types(trace);
+       if (ret) {
+               goto end;
+       }
+
        bt_ctf_attributes_freeze(trace->environment);
        trace->frozen = 1;
+end:
+       return ret;
 }
 
 static
This page took 0.02396 seconds and 4 git commands to generate.