From 93acce520f0c43306d5d58352cef20ee03f09d36 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Tue, 18 Feb 2020 13:44:25 -0800 Subject: [PATCH] libsysprof: plug leak and do less strdups Small leak based on the number of PROCESS frames we see. Easy to fix and easy to not do the g_strdup_printf() at all in those cases. --- src/libsysprof/sysprof-callgraph-profile.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libsysprof/sysprof-callgraph-profile.c b/src/libsysprof/sysprof-callgraph-profile.c index b8ed45b6..ce70d248 100644 --- a/src/libsysprof/sysprof-callgraph-profile.c +++ b/src/libsysprof/sysprof-callgraph-profile.c @@ -275,7 +275,6 @@ sysprof_callgraph_profile_generate_worker (GTask *task, while (sysprof_capture_reader_peek_type (reader, &type)) { const SysprofCaptureProcess *pr; - const gchar *cmdline; if (type != SYSPROF_CAPTURE_FRAME_PROCESS) { @@ -287,10 +286,13 @@ sysprof_callgraph_profile_generate_worker (GTask *task, if (NULL == (pr = sysprof_capture_reader_read_process (reader))) goto failure; - cmdline = g_strdup_printf ("[%s]", pr->cmdline); - g_hash_table_insert (cmdlines, - GINT_TO_POINTER (pr->frame.pid), - (gchar *)sysprof_callgraph_profile_intern_string (self, cmdline)); + if (!g_hash_table_contains (cmdlines, GINT_TO_POINTER (pr->frame.pid))) + { + g_autofree gchar *cmdline = g_strdup_printf ("[%s]", pr->cmdline); + g_hash_table_insert (cmdlines, + GINT_TO_POINTER (pr->frame.pid), + (gchar *)sysprof_callgraph_profile_intern_string (self, cmdline)); + } } if (g_task_return_error_if_cancelled (task))