* [PATCH 0/2] trace-cmd library: Fix memory leak in tracecmd_close()
@ 2022-03-24 0:08 Steven Rostedt
2022-03-24 0:08 ` [PATCH 1/2] trace-cmd library: Use cpu_data variable to shorten commands Steven Rostedt
2022-03-24 0:08 ` [PATCH 2/2] trace-cmd library: Fix memory leak of page_maps Steven Rostedt
0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-03-24 0:08 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
While writing the trace-cmd analyze command, I ran valgrind on it and found
that tracecmd_close() does not clean up the page_maps that were created, at
least not when reading a v6 file.
Steven Rostedt (Google) (2):
trace-cmd library: Use cpu_data variable to shorten commands
trace-cmd library: Fix memory leak of page_maps
lib/trace-cmd/trace-input.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] trace-cmd library: Use cpu_data variable to shorten commands
2022-03-24 0:08 [PATCH 0/2] trace-cmd library: Fix memory leak in tracecmd_close() Steven Rostedt
@ 2022-03-24 0:08 ` Steven Rostedt
2022-03-24 0:08 ` [PATCH 2/2] trace-cmd library: Fix memory leak of page_maps Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-03-24 0:08 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Instead of using handle->cpu_data[cpu] for all the references in
tracecmd_close(), just assign it to a variable cpu_data and use that. It
makes the code much more readable.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-input.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 31fde182a55e..358b47935602 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -4446,6 +4446,7 @@ void tracecmd_close(struct tracecmd_input *handle)
{
struct zchunk_cache *cache;
struct file_section *del_sec;
+ struct cpu_data *cpu_data;
int cpu;
int i;
@@ -4465,30 +4466,31 @@ void tracecmd_close(struct tracecmd_input *handle)
free_next(handle, cpu);
free_page(handle, cpu);
if (handle->cpu_data) {
- if (handle->cpu_data[cpu].kbuf) {
- kbuffer_free(handle->cpu_data[cpu].kbuf);
- if (handle->cpu_data[cpu].page_map)
- free_page_map(handle->cpu_data[cpu].page_map);
+ cpu_data = &handle->cpu_data[cpu];
+ if (cpu_data->kbuf) {
+ kbuffer_free(cpu_data->kbuf);
+ if (cpu_data->page_map)
+ free_page_map(cpu_data->page_map);
- if (handle->cpu_data[cpu].page_cnt)
+ if (cpu_data->page_cnt)
tracecmd_warning("%d pages still allocated on cpu %d%s",
- handle->cpu_data[cpu].page_cnt, cpu,
- show_records(handle->cpu_data[cpu].pages,
- handle->cpu_data[cpu].nr_pages));
- free(handle->cpu_data[cpu].pages);
+ cpu_data->page_cnt, cpu,
+ show_records(cpu_data->pages,
+ cpu_data->nr_pages));
+ free(cpu_data->pages);
}
- if (handle->cpu_data[cpu].compress.fd >= 0) {
- close(handle->cpu_data[cpu].compress.fd);
- unlink(handle->cpu_data[cpu].compress.file);
+ if (cpu_data->compress.fd >= 0) {
+ close(cpu_data->compress.fd);
+ unlink(cpu_data->compress.file);
}
- while (!list_empty(&handle->cpu_data[cpu].compress.cache)) {
- cache = container_of(handle->cpu_data[cpu].compress.cache.next,
+ while (!list_empty(&cpu_data->compress.cache)) {
+ cache = container_of(cpu_data->compress.cache.next,
struct zchunk_cache, list);
list_del(&cache->list);
free(cache->map);
free(cache);
}
- free(handle->cpu_data[cpu].compress.chunks);
+ free(cpu_data->compress.chunks);
}
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] trace-cmd library: Fix memory leak of page_maps
2022-03-24 0:08 [PATCH 0/2] trace-cmd library: Fix memory leak in tracecmd_close() Steven Rostedt
2022-03-24 0:08 ` [PATCH 1/2] trace-cmd library: Use cpu_data variable to shorten commands Steven Rostedt
@ 2022-03-24 0:08 ` Steven Rostedt
1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2022-03-24 0:08 UTC (permalink / raw)
To: linux-trace-devel; +Cc: Steven Rostedt (Google)
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
tracecmd_close() does not free up the page_maps for when it reads v6
files. This was found via valgrind.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
lib/trace-cmd/trace-input.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index 358b47935602..a902cfbdc567 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -4447,6 +4447,7 @@ void tracecmd_close(struct tracecmd_input *handle)
struct zchunk_cache *cache;
struct file_section *del_sec;
struct cpu_data *cpu_data;
+ struct page_map *page_map, *n;
int cpu;
int i;
@@ -4491,6 +4492,10 @@ void tracecmd_close(struct tracecmd_input *handle)
free(cache);
}
free(cpu_data->compress.chunks);
+ list_for_each_entry_safe(page_map, n, &cpu_data->page_maps, list) {
+ list_del(&page_map->list);
+ free(page_map);
+ }
}
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-24 0:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 0:08 [PATCH 0/2] trace-cmd library: Fix memory leak in tracecmd_close() Steven Rostedt
2022-03-24 0:08 ` [PATCH 1/2] trace-cmd library: Use cpu_data variable to shorten commands Steven Rostedt
2022-03-24 0:08 ` [PATCH 2/2] trace-cmd library: Fix memory leak of page_maps Steven Rostedt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.