From 37fcdd1964a5e821b24da7641d34775b90b5c711 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Sat, 18 Aug 2012 09:16:42 -0400 Subject: [PATCH] Fix: don't free unallocated index When opening a mmap trace, the index is not created so does not need to be freed, just add a check before freeing it. For clarity, this patch also allocates the packet_real_index just after the packet_cycles_index instead of waiting for the convert timestamp function. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- formats/ctf/ctf.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index c369d8d3..272e8c45 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -560,11 +560,15 @@ void ctf_init_pos(struct ctf_stream_pos *pos, int fd, int open_flags) 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; @@ -600,8 +604,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); } /* @@ -1855,9 +1861,6 @@ 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; -- 2.34.1