From 582986f5c99be1d161a37a791222b974c54dd462 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Fri, 12 May 2023 14:09:43 -0700 Subject: [PATCH] libsysprof-capture: free deduplicated array entries --- src/libsysprof-capture/sysprof-capture-reader.c | 7 +++++-- src/tests/test-capture.c | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c index 8f5e02e9..6b7fa051 100644 --- a/src/libsysprof-capture/sysprof-capture-reader.c +++ b/src/libsysprof-capture/sysprof-capture-reader.c @@ -1343,7 +1343,7 @@ array_append (const char ***files, *files = new_files; } - (*files)[*n_files] = new_element ? strdup (new_element) : NULL; + (*files)[*n_files] = new_element ? sysprof_strdup (new_element) : NULL; *n_files = *n_files + 1; assert (*n_files <= *n_files_allocated); @@ -1362,7 +1362,10 @@ array_deduplicate (const char **files, for (last_written = 0, next_to_read = 1; last_written <= next_to_read && next_to_read < *n_files;) { if (strcmp (files[next_to_read], files[last_written]) == 0) - next_to_read++; + { + free ((char *)files[next_to_read]); + next_to_read++; + } else files[++last_written] = files[next_to_read++]; } diff --git a/src/tests/test-capture.c b/src/tests/test-capture.c index c06ad209..a59dcab4 100644 --- a/src/tests/test-capture.c +++ b/src/tests/test-capture.c @@ -732,7 +732,7 @@ test_reader_writer_file (void) g_autofree gchar *data = NULL; g_autofree gchar *testfile = NULL; GByteArray *buf = g_byte_array_new (); - g_autofree const gchar **files = NULL; + const char **files; SysprofCaptureWriter *writer; SysprofCaptureReader *reader; SysprofCaptureFrameType type; @@ -799,6 +799,7 @@ test_reader_writer_file (void) g_assert_nonnull (files); g_assert_cmpstr (files[0], ==, testfile); g_assert_null (files[1]); + free (files); sysprof_capture_reader_reset (reader); new_fd = sysprof_memfd_create ("[sysprof-capture-file]");