Fix: don't free unallocated index
authorJulien Desfossez <jdesfossez@efficios.com>
Sat, 18 Aug 2012 13:16:42 +0000 (09:16 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 18 Aug 2012 13:16:42 +0000 (09:16 -0400)
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 <jdesfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c

index c369d8d36487ae79980a1caa747a79a4f2f916ec..272e8c45f4a6dc22270e6e7286bc64b723f448be 100644 (file)
@@ -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;
 
This page took 0.02756 seconds and 4 git commands to generate.