From: David Goulet Date: Fri, 26 Aug 2011 16:41:56 +0000 (-0400) Subject: Fix memory leaks and modify kernel session creation X-Git-Tag: v2.0-pre13~22 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f9815039b2c793170f6c411b3949aaa76d5b9141;p=lttng-tools.git Fix memory leaks and modify kernel session creation 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 --- diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index d088115f7..3014620ba 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -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; diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 29e05b9e9..edbdd643a 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -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) { diff --git a/ltt-sessiond/trace-kernel.c b/ltt-sessiond/trace-kernel.c index 3b51e3175..113eebea8 100644 --- a/ltt-sessiond/trace-kernel.c +++ b/ltt-sessiond/trace-kernel.c @@ -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); } diff --git a/ltt-sessiond/trace-kernel.h b/ltt-sessiond/trace-kernel.h index aaadbb28e..6bf5752fd 100644 --- a/ltt-sessiond/trace-kernel.h +++ b/ltt-sessiond/trace-kernel.h @@ -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); diff --git a/tests/test_kernel_data_trace.c b/tests/test_kernel_data_trace.c index 6bb7e67ad..e46d90186 100644 --- a/tests/test_kernel_data_trace.c +++ b/tests/test_kernel_data_trace.c @@ -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();