Fix list command
[lttng-tools.git] / src / bin / lttng / commands / list.c
index b73d5209f7f023408048fa27f90f9e0a3a45aeb3..4a53968740bd789aa8216bfda39029396c346b72 100644 (file)
@@ -260,6 +260,7 @@ static int list_ust_events(void)
        size = lttng_list_tracepoints(handle, &event_list);
        if (size < 0) {
                ERR("Unable to list UST events");
+               lttng_destroy_handle(handle);
                return size;
        }
 
@@ -280,10 +281,12 @@ static int list_ust_events(void)
        MSG("");
 
        free(event_list);
+       lttng_destroy_handle(handle);
 
        return CMD_SUCCESS;
 
 error:
+       lttng_destroy_handle(handle);
        return -1;
 }
 
@@ -311,6 +314,7 @@ static int list_kernel_events(void)
        size = lttng_list_tracepoints(handle, &event_list);
        if (size < 0) {
                ERR("Unable to list kernel events");
+               lttng_destroy_handle(handle);
                return size;
        }
 
@@ -324,9 +328,11 @@ static int list_kernel_events(void)
 
        free(event_list);
 
+       lttng_destroy_handle(handle);
        return CMD_SUCCESS;
 
 error:
+       lttng_destroy_handle(handle);
        return -1;
 }
 
@@ -600,10 +606,12 @@ int cmd_list(int argc, const char **argv)
                domain.type = LTTNG_DOMAIN_UST;
        }
 
-       handle = lttng_create_handle(session_name, &domain);
-       if (handle == NULL) {
-               ret = CMD_FATAL;
-               goto end;
+       if (opt_kernel || opt_userspace) {
+               handle = lttng_create_handle(session_name, &domain);
+               if (handle == NULL) {
+                       ret = CMD_FATAL;
+                       goto end;
+               }
        }
 
        if (session_name == NULL) {
@@ -666,7 +674,9 @@ int cmd_list(int argc, const char **argv)
                                }
 
                                /* Clean handle before creating a new one */
-                               lttng_destroy_handle(handle);
+                               if (handle) {
+                                       lttng_destroy_handle(handle);
+                               }
 
                                handle = lttng_create_handle(session_name, &domains[i]);
                                if (handle == NULL) {
@@ -686,7 +696,9 @@ end:
        if (domains) {
                free(domains);
        }
-       lttng_destroy_handle(handle);
+       if (handle) {
+               lttng_destroy_handle(handle);
+       }
 
        poptFreeContext(pc);
        return ret;
This page took 0.025792 seconds and 4 git commands to generate.