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.
This commit is contained in:
Christian Hergert
2020-02-18 13:44:25 -08:00
parent fdf912b716
commit 93acce520f

View File

@ -275,7 +275,6 @@ sysprof_callgraph_profile_generate_worker (GTask *task,
while (sysprof_capture_reader_peek_type (reader, &type)) while (sysprof_capture_reader_peek_type (reader, &type))
{ {
const SysprofCaptureProcess *pr; const SysprofCaptureProcess *pr;
const gchar *cmdline;
if (type != SYSPROF_CAPTURE_FRAME_PROCESS) 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))) if (NULL == (pr = sysprof_capture_reader_read_process (reader)))
goto failure; goto failure;
cmdline = g_strdup_printf ("[%s]", pr->cmdline); if (!g_hash_table_contains (cmdlines, GINT_TO_POINTER (pr->frame.pid)))
g_hash_table_insert (cmdlines, {
GINT_TO_POINTER (pr->frame.pid), g_autofree gchar *cmdline = g_strdup_printf ("[%s]", pr->cmdline);
(gchar *)sysprof_callgraph_profile_intern_string (self, 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)) if (g_task_return_error_if_cancelled (task))