linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf list: Fix memleak in print_sdt_events()
@ 2020-06-20  6:46 Wei Li
  0 siblings, 0 replies; only message in thread
From: Wei Li @ 2020-06-20  6:46 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim
  Cc: Peter Zijlstra, Ingo Molnar, guohanjun, linux-kernel

Valgrind check info:
==30629== Command: ./perf list sdt
==30629==
==30629==
==30629== HEAP SUMMARY:
==30629==     in use at exit: 12,226 bytes in 195 blocks
==30629==   total heap usage: 3,239 allocs, 3,044 frees, 3,546,759 bytes allocated
==30629==
==30629== 8,028 bytes in 115 blocks are definitely lost in loss record 54 of 54
==30629==    at 0x4885E44: realloc (vg_replace_malloc.c:785)
==30629==    by 0x56468C3: __vasprintf_chk (in /usr/lib64/libc-2.28.so)
==30629==    by 0x5646723: __asprintf_chk (in /usr/lib64/libc-2.28.so)
==30629==    by 0x4E2C3F: asprintf (stdio2.h:181)
==30629==    by 0x4E2C3F: print_sdt_events (parse-events.c:2611)
==30629==    by 0x446587: cmd_list (builtin-list.c:87)
==30629==    by 0x4B8947: run_builtin (perf.c:312)
==30629==    by 0x4B8C13: handle_internal_command (perf.c:364)
==30629==    by 0x434717: run_argv (perf.c:408)
==30629==    by 0x434717: main (perf.c:538)
==30629==
==30629== LEAK SUMMARY:
==30629==    definitely lost: 8,028 bytes in 115 blocks
==30629==    indirectly lost: 0 bytes in 0 blocks
==30629==      possibly lost: 0 bytes in 0 blocks
==30629==    still reachable: 4,198 bytes in 80 blocks
==30629==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Wei Li <liwei391@huawei.com>
---
 tools/perf/util/parse-events.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 3decbb203846..b2acacd5646e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2579,13 +2579,12 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
 	struct probe_cache *pcache;
 	struct probe_cache_entry *ent;
 	struct strlist *bidlist, *sdtlist;
-	struct strlist_config cfg = {.dont_dupstr = true};
 	struct str_node *nd, *nd2;
 	char *buf, *path, *ptr = NULL;
 	bool show_detail = false;
 	int ret;
 
-	sdtlist = strlist__new(NULL, &cfg);
+	sdtlist = strlist__new(NULL, NULL);
 	if (!sdtlist) {
 		pr_debug("Failed to allocate new strlist for SDT\n");
 		return;
@@ -2610,8 +2609,10 @@ void print_sdt_events(const char *subsys_glob, const char *event_glob,
 				continue;
 			ret = asprintf(&buf, "%s:%s@%s", ent->pev.group,
 					ent->pev.event, nd->s);
-			if (ret > 0)
+			if (ret > 0) {
 				strlist__add(sdtlist, buf);
+				free(buf);
+			}
 		}
 		probe_cache__delete(pcache);
 	}
-- 
2.19.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-20  6:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20  6:46 [PATCH] perf list: Fix memleak in print_sdt_events() Wei Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).