Improve error handling of lttng cli
[lttng-tools.git] / src / bin / lttng / commands / create.c
index 99e5daa932511bd0b891a773df2be7dc5399a55d..f60fe619e223e0db9c5686f0a62a5c73362bd02d 100644 (file)
@@ -101,9 +101,8 @@ static int create_session()
                        goto error;
                }
 
-               ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME
-                                       "/%s-%s", alloc_path, session_name, datetime);
-
+               ret = asprintf(&traces_path, "%s/" DEFAULT_TRACE_DIR_NAME "/%s-%s",
+                               alloc_path, session_name, datetime);
                if (ret < 0) {
                        perror("asprintf trace dir name");
                        ret = CMD_ERROR;
@@ -115,7 +114,7 @@ static int create_session()
 
        ret = lttng_create_session(session_name, traces_path);
        if (ret < 0) {
-               ret = CMD_ERROR;
+               /* Don't set ret so lttng can interpret the sessiond error. */
                goto error;
        }
 
@@ -132,6 +131,10 @@ static int create_session()
        ret = CMD_SUCCESS;
 
 error:
+       if (opt_session_name == NULL) {
+               free(session_name);
+       }
+
        if (alloc_path) {
                free(alloc_path);
        }
@@ -175,5 +178,6 @@ int cmd_create(int argc, const char **argv)
        ret = create_session();
 
 end:
+       poptFreeContext(pc);
        return ret;
 }
This page took 0.029343 seconds and 4 git commands to generate.