From 5201650b2174730c54927bca781becf73315bac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 8 May 2024 22:59:44 +0200 Subject: [PATCH 1/7] glocalfile: Trash, free values when done avoiding leaks on early returns In glocalfile we're allocating some temporary strings but we don't free them on early returns, so free them once done and unset the variables to prevent them being used incorrectly. --- gio/glocalfile.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gio/glocalfile.c b/gio/glocalfile.c index ceb888ad8..56ee5e5b4 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -2284,6 +2284,7 @@ g_local_file_trash (GFile *file, data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n", original_name_escaped, delete_time); g_free (delete_time); + g_clear_pointer (&original_name_escaped, g_free); if (!g_file_set_contents_full (infofile, data, -1, G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING, @@ -2291,6 +2292,7 @@ g_local_file_trash (GFile *file, { g_unlink (infofile); + g_free (data); g_free (filesdir); g_free (trashname); g_free (infofile); @@ -2298,6 +2300,8 @@ g_local_file_trash (GFile *file, return FALSE; } + g_clear_pointer (&data, g_free); + /* TODO: Maybe we should verify that you can delete the file from the trash * before moving it? OTOH, that is hard, as it needs a recursive scan */ @@ -2341,9 +2345,6 @@ g_local_file_trash (GFile *file, /* TODO: Do we need to update mtime/atime here after the move? */ g_free (infofile); - g_free (data); - - g_free (original_name_escaped); g_free (trashname); return TRUE; From e4d369d5f4defe54ef55954685b3275bcec0a2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 8 May 2024 23:02:39 +0200 Subject: [PATCH 2/7] gio/tests/gsettings: Cleanup allocated new locales --- gio/tests/gsettings.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gio/tests/gsettings.c b/gio/tests/gsettings.c index 6995feefd..b12d25973 100644 --- a/gio/tests/gsettings.c +++ b/gio/tests/gsettings.c @@ -924,6 +924,8 @@ test_l10n_time (void) g_assert_true (original_locale != (locale_t) 0); new_locale = duplocale (original_locale); g_assert_true (new_locale != (locale_t) 0); + g_clear_pointer (&new_locale, freelocale); + new_locale = newlocale (LC_TIME_MASK, "C", new_locale); g_assert_true (new_locale != (locale_t) 0); result = uselocale (new_locale); @@ -936,6 +938,7 @@ test_l10n_time (void) g_assert_cmpstr (str, ==, "12:00 AM"); g_free (str); + g_clear_pointer (&new_locale, freelocale); str = NULL; new_locale = newlocale (LC_TIME_MASK, "de_DE.UTF-8", new_locale); @@ -964,7 +967,7 @@ test_l10n_time (void) result = uselocale (original_locale); g_assert_true (result == new_locale); - freelocale (new_locale); + g_clear_pointer (&new_locale, freelocale); g_object_unref (settings); #endif From a2111bec6956d22b2113599c62c174e89c37685e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 8 May 2024 23:03:03 +0200 Subject: [PATCH 3/7] glib/tests/unicode: Cleanup allocated old locale if tests is skipped --- glib/tests/unicode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/glib/tests/unicode.c b/glib/tests/unicode.c index e91425aa7..cb74068a5 100644 --- a/glib/tests/unicode.c +++ b/glib/tests/unicode.c @@ -525,6 +525,7 @@ test_turkish_strupdown (void) if (oldlocale == NULL) { g_test_skip ("locale tr_TR not available"); + g_free (old_lang); return; } From c6770f964c8489b7bec42ecf8be7a2175f821ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 9 May 2024 16:59:57 +0200 Subject: [PATCH 4/7] glib/tests/gutils-user-database: Add test dependency on preload library We do preload the library but that's not set as test dependency and so it may not be built --- glib/tests/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/tests/meson.build b/glib/tests/meson.build index 92486cfac..c448b8156 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -263,7 +263,7 @@ else glib_tests += { 'gutils-user-database' : { - 'depends' : [], + 'depends' : getpwuid_preload, 'env' : { var_preload: getpwuid_preload.full_path() }, From 5fc08f60b57e01b11c2a4d707121d8cd38979f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 9 May 2024 17:47:04 +0200 Subject: [PATCH 5/7] girepository/introspection: Properly check for sanitizer value The sanitizer option is set to 'none' when not used --- girepository/introspection/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/girepository/introspection/meson.build b/girepository/introspection/meson.build index 9405686c1..b23d04884 100644 --- a/girepository/introspection/meson.build +++ b/girepository/introspection/meson.build @@ -9,7 +9,7 @@ gi_gen_shared_sources = [ gi_gen_env_variables = environment() -if get_option('b_sanitize') != '' +if get_option('b_sanitize') != 'none' gi_gen_env_variables.append( 'ASAN_OPTIONS', 'verify_asan_link_order=0', separator: ',') endif From 116312f089a2142fc8a20353543d805f01085458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 10 May 2024 01:17:15 +0200 Subject: [PATCH 6/7] glib/tests/mapping: Check the exit status of the child process In this way if it fails for some memory error we can track it --- glib/tests/mapping.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/glib/tests/mapping.c b/glib/tests/mapping.c index 99cb8eee0..5fcde83ae 100644 --- a/glib/tests/mapping.c +++ b/glib/tests/mapping.c @@ -22,6 +22,7 @@ #ifdef G_OS_UNIX #include +#include #endif #ifdef G_OS_WIN32 #include @@ -201,8 +202,10 @@ test_child_private (void) gsize len; gchar *child_argv[4]; GPid child_pid; + GSpawnFlags spawn_flags = G_SPAWN_DEFAULT; #ifndef G_OS_WIN32 GMainLoop *loop; + int wait_status; #endif gchar pid[100]; gchar *dir, *global_filename, *childname; @@ -221,6 +224,7 @@ test_child_private (void) #ifndef G_OS_WIN32 signal (SIGUSR1, handle_usr1); + spawn_flags |= G_SPAWN_DO_NOT_REAP_CHILD; #endif g_snprintf (pid, sizeof(pid), "%d", getpid ()); @@ -230,7 +234,7 @@ test_child_private (void) child_argv[3] = NULL; result = g_spawn_async (dir, child_argv, NULL, - 0, NULL, NULL, &child_pid, &error); + spawn_flags, NULL, NULL, &child_pid, &error); g_assert_no_error (error); g_assert_true (result); g_test_message ("test_child_private: child spawned"); @@ -261,6 +265,10 @@ test_child_private (void) #ifndef G_OS_WIN32 g_idle_add (check_stop, loop); g_main_loop_run (loop); + waitpid (child_pid, &wait_status, 0); + g_test_message ("Child exited with status %d", wait_status); + g_spawn_check_wait_status (wait_status, &error); + g_assert_no_error (error); #else g_usleep (2000000); #endif From 9c611f6ef94fce218172c2f22b40d34b6bdbed1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 10 May 2024 01:17:41 +0200 Subject: [PATCH 7/7] glib/tests/mapping: Unref the mapped file on exit --- glib/tests/mapping.c | 1 + 1 file changed, 1 insertion(+) diff --git a/glib/tests/mapping.c b/glib/tests/mapping.c index 5fcde83ae..bbd4de8b0 100644 --- a/glib/tests/mapping.c +++ b/glib/tests/mapping.c @@ -125,6 +125,7 @@ child_main (void) g_free (childname); g_free (global_filename); g_free (dir); + g_mapped_file_unref (map); signal_parent (NULL); }