Fix: only free trace_path when it is dynamically allocated
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 14 Jan 2019 22:13:32 +0000 (17:13 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 21 Jan 2019 18:39:25 +0000 (13:39 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/view.c

index faca60de8b980adfe60afcb2ac68a7c202a65595..0325e505c505fab3dab2bc666fa7caec40822aa4 100644 (file)
@@ -302,6 +302,7 @@ static int view_trace(void)
        int ret;
        char *session_name, *trace_path = NULL;
        struct lttng_session *sessions = NULL;
        int ret;
        char *session_name, *trace_path = NULL;
        struct lttng_session *sessions = NULL;
+       bool free_trace_path = false;
 
        /*
         * Safety net. If lttng is suid at some point for *any* useless reasons,
 
        /*
         * Safety net. If lttng is suid at some point for *any* useless reasons,
@@ -379,6 +380,7 @@ static int view_trace(void)
                                ret = CMD_ERROR;
                                goto free_sessions;
                        }
                                ret = CMD_ERROR;
                                goto free_sessions;
                        }
+                       free_trace_path = true;
                } else {
                        /* Get file system session path. */
                        trace_path = sessions[i].path;
                } else {
                        /* Get file system session path. */
                        trace_path = sessions[i].path;
@@ -396,7 +398,7 @@ static int view_trace(void)
        }
 
 free_sessions:
        }
 
 free_sessions:
-       if (session_live_mode) {
+       if (session_live_mode && free_trace_path) {
                free(trace_path);
        }
        free(sessions);
                free(trace_path);
        }
        free(sessions);
This page took 0.02608 seconds and 4 git commands to generate.