Merge branch 'backport-4059-leak-fixes-glib-2-80' into 'glib-2-80'

Partially backport !4059 “tests: Fix various memory leaks and valgrind / ASAN errors” to glib-2-80

See merge request GNOME/glib!4070
This commit is contained in:
Philip Withnall 2024-05-15 13:55:16 +00:00
commit c2ec54d641
6 changed files with 21 additions and 7 deletions

View File

@ -2284,6 +2284,7 @@ g_local_file_trash (GFile *file,
data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n", data = g_strdup_printf ("[Trash Info]\nPath=%s\nDeletionDate=%s\n",
original_name_escaped, delete_time); original_name_escaped, delete_time);
g_free (delete_time); g_free (delete_time);
g_clear_pointer (&original_name_escaped, g_free);
if (!g_file_set_contents_full (infofile, data, -1, if (!g_file_set_contents_full (infofile, data, -1,
G_FILE_SET_CONTENTS_CONSISTENT | G_FILE_SET_CONTENTS_ONLY_EXISTING, 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_unlink (infofile);
g_free (data);
g_free (filesdir); g_free (filesdir);
g_free (trashname); g_free (trashname);
g_free (infofile); g_free (infofile);
@ -2298,6 +2300,8 @@ g_local_file_trash (GFile *file,
return FALSE; return FALSE;
} }
g_clear_pointer (&data, g_free);
/* TODO: Maybe we should verify that you can delete the file from the trash /* 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 * 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? */ /* TODO: Do we need to update mtime/atime here after the move? */
g_free (infofile); g_free (infofile);
g_free (data);
g_free (original_name_escaped);
g_free (trashname); g_free (trashname);
return TRUE; return TRUE;

View File

@ -924,6 +924,8 @@ test_l10n_time (void)
g_assert_true (original_locale != (locale_t) 0); g_assert_true (original_locale != (locale_t) 0);
new_locale = duplocale (original_locale); new_locale = duplocale (original_locale);
g_assert_true (new_locale != (locale_t) 0); g_assert_true (new_locale != (locale_t) 0);
g_clear_pointer (&new_locale, freelocale);
new_locale = newlocale (LC_TIME_MASK, "C", new_locale); new_locale = newlocale (LC_TIME_MASK, "C", new_locale);
g_assert_true (new_locale != (locale_t) 0); g_assert_true (new_locale != (locale_t) 0);
result = uselocale (new_locale); result = uselocale (new_locale);
@ -936,6 +938,7 @@ test_l10n_time (void)
g_assert_cmpstr (str, ==, "12:00 AM"); g_assert_cmpstr (str, ==, "12:00 AM");
g_free (str); g_free (str);
g_clear_pointer (&new_locale, freelocale);
str = NULL; str = NULL;
new_locale = newlocale (LC_TIME_MASK, "de_DE.UTF-8", new_locale); new_locale = newlocale (LC_TIME_MASK, "de_DE.UTF-8", new_locale);
@ -964,7 +967,7 @@ test_l10n_time (void)
result = uselocale (original_locale); result = uselocale (original_locale);
g_assert_true (result == new_locale); g_assert_true (result == new_locale);
freelocale (new_locale); g_clear_pointer (&new_locale, freelocale);
g_object_unref (settings); g_object_unref (settings);
#endif #endif

View File

@ -9,7 +9,7 @@ gi_gen_shared_sources = [
gi_gen_env_variables = environment() gi_gen_env_variables = environment()
if get_option('b_sanitize') != '' if get_option('b_sanitize') != 'none'
gi_gen_env_variables.append( gi_gen_env_variables.append(
'ASAN_OPTIONS', 'verify_asan_link_order=0', separator: ',') 'ASAN_OPTIONS', 'verify_asan_link_order=0', separator: ',')
endif endif

View File

@ -22,6 +22,7 @@
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h>
#endif #endif
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
#include <process.h> #include <process.h>
@ -124,6 +125,7 @@ child_main (void)
g_free (childname); g_free (childname);
g_free (global_filename); g_free (global_filename);
g_free (dir); g_free (dir);
g_mapped_file_unref (map);
signal_parent (NULL); signal_parent (NULL);
} }
@ -201,8 +203,10 @@ test_child_private (void)
gsize len; gsize len;
gchar *child_argv[4]; gchar *child_argv[4];
GPid child_pid; GPid child_pid;
GSpawnFlags spawn_flags = G_SPAWN_DEFAULT;
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
GMainLoop *loop; GMainLoop *loop;
int wait_status;
#endif #endif
gchar pid[100]; gchar pid[100];
gchar *dir, *global_filename, *childname; gchar *dir, *global_filename, *childname;
@ -221,6 +225,7 @@ test_child_private (void)
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
signal (SIGUSR1, handle_usr1); signal (SIGUSR1, handle_usr1);
spawn_flags |= G_SPAWN_DO_NOT_REAP_CHILD;
#endif #endif
g_snprintf (pid, sizeof(pid), "%d", getpid ()); g_snprintf (pid, sizeof(pid), "%d", getpid ());
@ -230,7 +235,7 @@ test_child_private (void)
child_argv[3] = NULL; child_argv[3] = NULL;
result = g_spawn_async (dir, child_argv, 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_no_error (error);
g_assert_true (result); g_assert_true (result);
g_test_message ("test_child_private: child spawned"); g_test_message ("test_child_private: child spawned");
@ -261,6 +266,10 @@ test_child_private (void)
#ifndef G_OS_WIN32 #ifndef G_OS_WIN32
g_idle_add (check_stop, loop); g_idle_add (check_stop, loop);
g_main_loop_run (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 #else
g_usleep (2000000); g_usleep (2000000);
#endif #endif

View File

@ -263,7 +263,7 @@ else
glib_tests += { glib_tests += {
'gutils-user-database' : { 'gutils-user-database' : {
'depends' : [], 'depends' : getpwuid_preload,
'env' : { 'env' : {
var_preload: getpwuid_preload.full_path() var_preload: getpwuid_preload.full_path()
}, },

View File

@ -525,6 +525,7 @@ test_turkish_strupdown (void)
if (oldlocale == NULL) if (oldlocale == NULL)
{ {
g_test_skip ("locale tr_TR not available"); g_test_skip ("locale tr_TR not available");
g_free (old_lang);
return; return;
} }