+
+int ctf_destroy_metadata(struct ctf_trace *trace)
+{
+ int i;
+ struct ctf_file_stream *metadata_stream;
+
+ if (trace->streams) {
+ for (i = 0; i < trace->streams->len; i++) {
+ struct ctf_stream_declaration *stream;
+ int j;
+
+ stream = g_ptr_array_index(trace->streams, i);
+ if (!stream)
+ continue;
+ for (j = 0; j < stream->streams->len; j++) {
+ struct ctf_stream_definition *stream_def;
+ int k;
+
+ stream_def = g_ptr_array_index(stream->streams, j);
+ if (!stream_def)
+ continue;
+ for (k = 0; k < stream_def->events_by_id->len; k++) {
+ struct ctf_event_definition *event;
+
+ event = g_ptr_array_index(stream_def->events_by_id, k);
+ if (!event)
+ continue;
+ if (&event->event_fields->p)
+ bt_definition_unref(&event->event_fields->p);
+ if (&event->event_context->p)
+ bt_definition_unref(&event->event_context->p);
+ g_free(event);
+ }
+ if (&stream_def->trace_packet_header->p)
+ bt_definition_unref(&stream_def->trace_packet_header->p);
+ if (&stream_def->stream_event_header->p)
+ bt_definition_unref(&stream_def->stream_event_header->p);
+ if (&stream_def->stream_packet_context->p)
+ bt_definition_unref(&stream_def->stream_packet_context->p);
+ if (&stream_def->stream_event_context->p)
+ bt_definition_unref(&stream_def->stream_event_context->p);
+ g_ptr_array_free(stream_def->events_by_id, TRUE);
+ g_free(stream_def);
+ }
+ if (stream->event_header_decl)
+ bt_declaration_unref(&stream->event_header_decl->p);
+ if (stream->event_context_decl)
+ bt_declaration_unref(&stream->event_context_decl->p);
+ if (stream->packet_context_decl)
+ bt_declaration_unref(&stream->packet_context_decl->p);
+ g_ptr_array_free(stream->streams, TRUE);
+ g_ptr_array_free(stream->events_by_id, TRUE);
+ g_hash_table_destroy(stream->event_quark_to_id);
+ bt_free_declaration_scope(stream->declaration_scope);
+ g_free(stream);
+ }
+ g_ptr_array_free(trace->streams, TRUE);
+ }
+
+ if (trace->event_declarations) {
+ for (i = 0; i < trace->event_declarations->len; i++) {
+ struct bt_ctf_event_decl *event_decl;
+ struct ctf_event_declaration *event;
+
+ event_decl = g_ptr_array_index(trace->event_declarations, i);
+ if (event_decl->context_decl)
+ g_ptr_array_free(event_decl->context_decl, TRUE);
+ if (event_decl->fields_decl)
+ g_ptr_array_free(event_decl->fields_decl, TRUE);
+ if (event_decl->packet_header_decl)
+ g_ptr_array_free(event_decl->packet_header_decl, TRUE);
+ if (event_decl->event_context_decl)
+ g_ptr_array_free(event_decl->event_context_decl, TRUE);
+ if (event_decl->event_header_decl)
+ g_ptr_array_free(event_decl->event_header_decl, TRUE);
+ if (event_decl->packet_context_decl)
+ g_ptr_array_free(event_decl->packet_context_decl, TRUE);
+
+ event = &event_decl->parent;
+ if (event->fields_decl)
+ bt_declaration_unref(&event->fields_decl->p);
+ if (event->context_decl)
+ bt_declaration_unref(&event->context_decl->p);
+ bt_free_declaration_scope(event->declaration_scope);
+
+ g_free(event);
+ }
+ g_ptr_array_free(trace->event_declarations, TRUE);
+ }
+ if (trace->packet_header_decl)
+ bt_declaration_unref(&trace->packet_header_decl->p);
+
+ bt_free_declaration_scope(trace->root_declaration_scope);
+ bt_free_declaration_scope(trace->declaration_scope);
+
+ g_hash_table_destroy(trace->callsites);
+ g_hash_table_destroy(trace->parent.clocks);
+
+ metadata_stream = container_of(trace->metadata, struct ctf_file_stream, parent);
+ g_free(metadata_stream);
+
+ return 0;
+}