lttng command line UI: fix allocation/free
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 16 Jul 2011 16:06:21 +0000 (12:06 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Sat, 16 Jul 2011 19:03:41 +0000 (15:03 -0400)
Freeing non-dynamically allocated memory is never a good idea.
Also fixing 2 memory leaks.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
lttng/commands/destroy.c
lttng/commands/disable_events.c
lttng/commands/enable_events.c
lttng/commands/start.c
lttng/commands/stop.c
lttng/utils.c

index d7c01097fdf8d03e029102bc03813112a4069c6d..743d899786a637b58b7b773012832c4426708707 100644 (file)
@@ -97,7 +97,9 @@ static int destroy_session()
        ret = CMD_SUCCESS;
 
 free_name:
-       free(session_name);
+       if (opt_session_name == NULL) {
+               free(session_name);
+       }
 error:
        return ret;
 }
index 04a8c0a62f97ad1afaa7ad0e263eac8916586b94..3cd130e571ff8d66996ee59c943259b9b72d6ab6 100644 (file)
@@ -83,7 +83,7 @@ static void usage(FILE *ofp)
 static int disable_events(void)
 {
        int err, ret = CMD_SUCCESS;
-       char *event_name, *channel_name;
+       char *event_name, *channel_name = NULL;
        struct lttng_event ev;
 
        if (set_session_name(opt_session_name) < 0) {
@@ -147,6 +147,9 @@ static int disable_events(void)
        }
 
 error:
+       if (opt_channel_name == NULL) {
+               free(channel_name);
+       }
        return ret;
 }
 
index d4af4b3d3a1e647ae9b42dcb2738279ddcfbd830..718e4b3c30b3894d47d20026f4103552c3f0988c 100644 (file)
@@ -152,7 +152,7 @@ error:
 static int enable_events(void)
 {
        int err, ret = CMD_SUCCESS;
-       char *event_name, *channel_name;
+       char *event_name, *channel_name = NULL;
        struct lttng_event ev;
 
        if (set_session_name(opt_session_name) < 0) {
@@ -235,6 +235,9 @@ static int enable_events(void)
        }
 
 error:
+       if (opt_channel_name == NULL) {
+               free(channel_name);
+       }
        return ret;
 }
 
index 1a3e568ed6df10115f90313c6ce9b9ee894539ed..e9423170e8773e2a99dd6544f8efe0ad0719aeaf 100644 (file)
@@ -85,7 +85,9 @@ static int start_tracing(void)
        MSG("Tracing started for session %s", session_name);
 
 free_name:
-       free(session_name);
+       if (opt_session_name == NULL) {
+               free(session_name);
+       }
 error:
        return ret;
 }
index 56edc2d6de64010d6c701645d375d075bed645be..664637873f6c980ee22499192317f25aeeca1ac2 100644 (file)
@@ -83,7 +83,9 @@ static int stop_tracing(void)
        MSG("Tracing stopped for session %s", session_name);
 
 free_name:
-       free(session_name);
+       if (opt_session_name == NULL) {
+               free(session_name);
+       }
 error:
        return ret;
 }
index 2cb77568e339433062408f8c69a8f3fac072fd98..1b2138cedbd1531afe12db32a4cb463f84670afc 100644 (file)
@@ -58,18 +58,19 @@ int set_session_name(char *name)
        int ret;
        char *session_name;
 
-       if (name != NULL) {
-               session_name = name;
-       } else {
+       if (!name) {
                session_name = get_session_name();
                if (session_name == NULL) {
                        ret = -1;
                        goto error;
                }
+       } else {
+               session_name = name;
        }
 
        lttng_set_session_name(session_name);
-       free(session_name);
+       if (!name)
+               free(session_name);
 
        ret = 0;
 
This page took 0.040672 seconds and 4 git commands to generate.