Fix memory leaks and modify kernel session creation
authorDavid Goulet <david.goulet@polymtl.ca>
Fri, 26 Aug 2011 16:41:56 +0000 (12:41 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Fri, 26 Aug 2011 16:41:56 +0000 (12:41 -0400)
Set the path of the kernel session in trace-kernel.c in order to
centralize that setup at only one place.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/kernel-ctl.c
ltt-sessiond/main.c
ltt-sessiond/trace-kernel.c
ltt-sessiond/trace-kernel.h
tests/test_kernel_data_trace.c

index d088115f78380cddc15e1f038b1980ffa16ed4b1..3014620babe5ff4cea11ce1253eed43fa85d9862 100644 (file)
@@ -102,7 +102,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd)
        struct ltt_kernel_session *lks;
 
        /* Allocate data structure */
-       lks = trace_kernel_create_session();
+       lks = trace_kernel_create_session(session->path);
        if (lks == NULL) {
                ret = -1;
                goto error;
index 29e05b9e9ed23cbcaf6b5c9b770caf1388a574b2..edbdd643a84f5e1c69b3118663af7fafb2b274fa 100644 (file)
@@ -1561,13 +1561,6 @@ static int create_kernel_session(struct ltt_session *session)
                session->kernel_session->consumer_fd = kconsumerd_cmd_sock;
        }
 
-       ret = asprintf(&session->kernel_session->trace_path, "%s/kernel",
-                       session->path);
-       if (ret < 0) {
-               perror("asprintf kernel traces path");
-               goto error;
-       }
-
        ret = mkdir_recursive(session->kernel_session->trace_path,
                        S_IRWXU | S_IRWXG, geteuid(), allowed_group());
        if (ret < 0) {
index 3b51e3175da5fcde34a648e79555eabb22aed089..113eebea8d3b012d4dcfd34f5009f08c2a11c159 100644 (file)
@@ -80,8 +80,9 @@ error:
  *
  * Return pointer to structure or NULL.
  */
-struct ltt_kernel_session *trace_kernel_create_session(void)
+struct ltt_kernel_session *trace_kernel_create_session(char *path)
 {
+       int ret;
        struct ltt_kernel_session *lks;
 
        /* Allocate a new ltt kernel session */
@@ -100,6 +101,13 @@ struct ltt_kernel_session *trace_kernel_create_session(void)
        lks->consumer_fd = 0;
        CDS_INIT_LIST_HEAD(&lks->channel_list.head);
 
+       /* Set session path */
+       ret = asprintf(&lks->trace_path, "%s/kernel", path);
+       if (ret < 0) {
+               perror("asprintf kernel traces path");
+               goto error;
+       }
+
        return lks;
 
 error:
@@ -292,10 +300,10 @@ void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream)
        DBG("[trace] Closing stream fd %d", stream->fd);
        /* Close kernel fd */
        close(stream->fd);
-       free(stream->pathname);
-
        /* Remove from stream list */
        cds_list_del(&stream->list);
+
+       free(stream->pathname);
        free(stream);
 }
 
@@ -307,11 +315,12 @@ void trace_kernel_destroy_event(struct ltt_kernel_event *event)
        DBG("[trace] Closing event fd %d", event->fd);
        /* Close kernel fd */
        close(event->fd);
-       /* Free attributes */
-       free(event->event);
 
        /* Remove from event list */
        cds_list_del(&event->list);
+
+       free(event->event);
+       free(event->ctx);
        free(event);
 }
 
@@ -326,9 +335,6 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
        DBG("[trace] Closing channel fd %d", channel->fd);
        /* Close kernel fd */
        close(channel->fd);
-       free(channel->pathname);
-       /* Free attributes structure */
-       free(channel->channel);
 
        /* For each stream in the channel list */
        cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) {
@@ -342,6 +348,10 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel)
 
        /* Remove from channel list */
        cds_list_del(&channel->list);
+
+       free(channel->pathname);
+       free(channel->channel);
+       free(channel->ctx);
        free(channel);
 }
 
@@ -353,9 +363,9 @@ void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata)
        DBG("[trace] Closing metadata fd %d", metadata->fd);
        /* Close kernel fd */
        close(metadata->fd);
-       /* Free attributes */
-       free(metadata->conf);
 
+       free(metadata->conf);
+       free(metadata->pathname);
        free(metadata);
 }
 
@@ -369,6 +379,7 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session)
        DBG("[trace] Closing session fd %d", session->fd);
        /* Close kernel fds */
        close(session->fd);
+
        if (session->metadata_stream_fd != 0) {
                DBG("[trace] Closing metadata stream fd %d", session->metadata_stream_fd);
                close(session->metadata_stream_fd);
@@ -382,5 +393,6 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session)
                trace_kernel_destroy_channel(channel);
        }
 
+       free(session->trace_path);
        free(session);
 }
index aaadbb28e52d021eb325ccc9113ad08765eee8a9..6bf5752fd76853686cf8f9aa1f194f6c588dbf20 100644 (file)
@@ -102,7 +102,7 @@ struct ltt_kernel_channel *trace_kernel_get_channel_by_name(
 /*
  * Create functions malloc() the data structure.
  */
-struct ltt_kernel_session *trace_kernel_create_session(void);
+struct ltt_kernel_session *trace_kernel_create_session(char *path);
 struct ltt_kernel_channel *trace_kernel_create_channel(struct lttng_channel *chan, char *path);
 struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev);
 struct ltt_kernel_metadata *trace_kernel_create_metadata(char *path);
index 6bb7e67add8ef2fde39c82aeda07ff2176d99cf3..e46d9018696417000f325ddf8a0d8111ce48a79b 100644 (file)
@@ -62,7 +62,7 @@ static char *get_random_string(void)
 static void create_one_kernel_session(void)
 {
        printf("Create kernel session: ");
-       kern = trace_kernel_create_session();
+       kern = trace_kernel_create_session(PATH1);
        assert(kern != NULL);
        PRINT_OK();
 
This page took 0.02911 seconds and 4 git commands to generate.