diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-02-23 01:13:00 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2022-02-23 10:33:58 -0500 |
commit | f35dc1dc736ef0982739e0f8aa380d85a42fce45 (patch) | |
tree | 0679c731ded98b7c7677eeed7dadd35ed19c264c | |
parent | 8fc17aa859c2aa5481409e0fa6099e24bf2b31ad (diff) | |
download | libtracefs-f35dc1dc736ef0982739e0f8aa380d85a42fce45.tar.gz |
libtracefs: Fix various memory issues
Running "make test_mem" which calls valgrind on the unit tests, uncovered
various issues with allocations, initialization and freeing.
Link: https://lore.kernel.org/linux-trace-devel/20220223011300.377389b9@rorschach.local.home
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | src/tracefs-dynevents.c | 3 | ||||
-rw-r--r-- | src/tracefs-hist.c | 2 | ||||
-rw-r--r-- | src/tracefs-sqlhist.c | 2 | ||||
-rw-r--r-- | src/tracefs-utils.c | 10 | ||||
-rw-r--r-- | utest/tracefs-utest.c | 2 |
5 files changed, 11 insertions, 8 deletions
diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c index ddebb6b..61804b9 100644 --- a/src/tracefs-dynevents.c +++ b/src/tracefs-dynevents.c @@ -120,7 +120,7 @@ static int dyn_generic_parse(struct dyn_events_desc *desc, const char *group, struct tracefs_dynevent *dyn; char *word; char *format = NULL; - char *address; + char *address = NULL; char *system; char *prefix; char *event; @@ -582,6 +582,7 @@ tracefs_dynevent_get_all(unsigned int types, const char *system) all += count; /* Add a NULL pointer at the end */ all_events[all] = NULL; + free(events); } } diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c index 5a89be2..e688eb3 100644 --- a/src/tracefs-hist.c +++ b/src/tracefs-hist.c @@ -745,12 +745,14 @@ void tracefs_synth_free(struct tracefs_synth *synth) free(synth->end_hist); tracefs_list_free(synth->synthetic_fields); tracefs_list_free(synth->synthetic_args); + tracefs_list_free(synth->start_selection); tracefs_list_free(synth->start_keys); tracefs_list_free(synth->end_keys); tracefs_list_free(synth->start_vars); tracefs_list_free(synth->end_vars); free(synth->start_filter); free(synth->end_filter); + free(synth->start_type); tep_unref(synth->tep); diff --git a/src/tracefs-sqlhist.c b/src/tracefs-sqlhist.c index ac4903c..9811362 100644 --- a/src/tracefs-sqlhist.c +++ b/src/tracefs-sqlhist.c @@ -1538,7 +1538,7 @@ static void free_sql_table(struct sql_table *table) return; while ((expr = table->exprs)) { - table->exprs = expr->next; + table->exprs = expr->free_list; free(expr); } diff --git a/src/tracefs-utils.c b/src/tracefs-utils.c index 0ad9a35..7b1f816 100644 --- a/src/tracefs-utils.c +++ b/src/tracefs-utils.c @@ -183,18 +183,16 @@ const char *tracefs_tracing_dir(void) */ char *tracefs_get_tracing_file(const char *name) { - static const char *tracing; + const char *tracing; char *file; int ret; if (!name) return NULL; - if (!tracing) { - tracing = trace_find_tracing_dir(); - if (!tracing) - return NULL; - } + tracing = tracefs_tracing_dir(); + if (!tracing) + return NULL; ret = asprintf(&file, "%s/%s", tracing, name); if (ret < 0) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index e8d5c69..0903243 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -430,6 +430,8 @@ static void test_synth_compare(struct test_synth *synth, struct tracefs_dynevent if (synth[i].match_name) { CU_TEST(strstr(format, synth[i].match_name) != NULL); } + free(event); + free(format); } CU_TEST(devents[i] == NULL); } |