X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=a2403a77ab8d8906e18e59cb41d6a68684e2ba7a;hp=f33fa3394ec52be5d11c4dd102ffb468025156ca;hb=86b06ede131de636cd9ee62ea79d37f86e75c257;hpb=03798a93f959f6c694fe98f5647481947607c604 diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index f33fa339..a2403a77 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -167,6 +167,9 @@ uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor, if (!stream_pos->packet_real_index) goto error; + if (stream_pos->packet_real_index->len <= 0) + continue; + if (type == BT_CLOCK_REAL) { index = &g_array_index(stream_pos->packet_real_index, struct packet_index, @@ -225,6 +228,9 @@ uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor, if (!stream_pos->packet_real_index) goto error; + if (stream_pos->packet_real_index->len <= 0) + continue; + if (type == BT_CLOCK_REAL) { index = &g_array_index(stream_pos->packet_real_index, struct packet_index, @@ -545,20 +551,15 @@ error: void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags) { pos->fd = fd; - pos->mmap_offset = 0; - pos->packet_size = 0; - pos->content_size = 0; - pos->content_size_loc = NULL; - pos->base_mma = NULL; - pos->offset = 0; - pos->dummy = false; - pos->cur_index = 0; - pos->packet_real_index = NULL; - if (fd >= 0) + if (fd >= 0) { pos->packet_cycles_index = g_array_new(FALSE, TRUE, sizeof(struct packet_index)); - else + pos->packet_real_index = g_array_new(FALSE, TRUE, + sizeof(struct packet_index)); + } else { pos->packet_cycles_index = NULL; + pos->packet_real_index = NULL; + } switch (open_flags & O_ACCMODE) { case O_RDONLY: pos->prot = PROT_READ; @@ -594,8 +595,10 @@ void ctf_fini_pos(struct ctf_stream_pos *pos) assert(0); } } - (void) g_array_free(pos->packet_cycles_index, TRUE); - (void) g_array_free(pos->packet_real_index, TRUE); + if (pos->packet_cycles_index) + (void) g_array_free(pos->packet_cycles_index, TRUE); + if (pos->packet_real_index) + (void) g_array_free(pos->packet_real_index, TRUE); } /* @@ -1005,6 +1008,7 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td, if (metadata_fp) { fp = metadata_fp; + metadata_stream->pos.fd = -1; } else { td->metadata = &metadata_stream->parent; metadata_stream->pos.fd = openat(td->dirfd, "metadata", O_RDONLY); @@ -1084,7 +1088,8 @@ end_packet_read: fclose(fp); free(buf); end_stream: - close(metadata_stream->pos.fd); + if (metadata_stream->pos.fd >= 0) + close(metadata_stream->pos.fd); if (ret) g_free(metadata_stream); return ret; @@ -1740,6 +1745,11 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td, if (ret) goto error_index; + /* + * For now, only a single slock is supported. + */ + file_stream->parent.current_clock = td->single_clock; + /* Add stream file to stream class */ g_ptr_array_add(file_stream->parent.stream_class->streams, &file_stream->parent); @@ -1842,8 +1852,8 @@ int ctf_convert_index_timestamp(struct trace_descriptor *tdp) cfs = container_of(stream, struct ctf_file_stream, parent); stream_pos = &cfs->pos; - stream_pos->packet_real_index = g_array_new(FALSE, TRUE, - sizeof(struct packet_index)); + if (!stream_pos->packet_cycles_index) + continue; for (k = 0; k < stream_pos->packet_cycles_index->len; k++) { struct packet_index *index;