diff --git a/gio/gbufferedoutputstream.c b/gio/gbufferedoutputstream.c index 8b2bcdc04..98bda501d 100644 --- a/gio/gbufferedoutputstream.c +++ b/gio/gbufferedoutputstream.c @@ -699,7 +699,7 @@ g_buffered_output_stream_flush_async (GOutputStream *stream, GTask *task; FlushData *fdata; - fdata = g_slice_new (FlushData); + fdata = g_slice_new0 (FlushData); fdata->flush_stream = TRUE; fdata->close_stream = FALSE; @@ -732,7 +732,7 @@ g_buffered_output_stream_close_async (GOutputStream *stream, GTask *task; FlushData *fdata; - fdata = g_slice_new (FlushData); + fdata = g_slice_new0 (FlushData); fdata->close_stream = TRUE; task = g_task_new (stream, cancellable, callback, data); diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 617a096fb..d0ffbace3 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -4698,6 +4698,8 @@ g_desktop_app_info_launch_action (GDesktopAppInfo *info, g_desktop_app_info_launch_uris_with_spawn (info, session_bus, exec_line, NULL, launch_context, _SPAWN_FLAGS_DEFAULT, NULL, NULL, NULL, NULL, -1, -1, -1, NULL); + + g_free (exec_line); } if (session_bus != NULL) diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 1c8fa42e8..83dff4342 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -1807,6 +1807,7 @@ _g_local_file_has_trash_dir (const char *dirname, dev_t dir_dev) if (mount == NULL || g_unix_mount_is_system_internal (mount)) { g_clear_pointer (&mount, g_unix_mount_free); + g_free (topdir); return FALSE; } diff --git a/gio/tests/appinfo.c b/gio/tests/appinfo.c index 2e69da051..ea4809d54 100644 --- a/gio/tests/appinfo.c +++ b/gio/tests/appinfo.c @@ -128,10 +128,10 @@ static void test_locale (const char *locale) { GAppInfo *appinfo; - const gchar *orig; + gchar *orig = NULL; const gchar *path; - orig = setlocale (LC_ALL, NULL); + orig = g_strdup (setlocale (LC_ALL, NULL)); g_setenv ("LANGUAGE", locale, TRUE); setlocale (LC_ALL, ""); @@ -161,6 +161,7 @@ test_locale (const char *locale) g_setenv ("LANGUAGE", orig, TRUE); setlocale (LC_ALL, ""); + g_free (orig); } static void @@ -380,6 +381,7 @@ test_associations (void) "cmdline-app-test", G_APP_INFO_CREATE_SUPPORTS_URIS, NULL); + g_free (cmdline); error = NULL; result = g_app_info_set_as_default_for_type (appinfo, "application/x-glib-test", &error); diff --git a/gio/tests/dbus-appinfo.c b/gio/tests/dbus-appinfo.c index ee73d5833..8961a5495 100644 --- a/gio/tests/dbus-appinfo.c +++ b/gio/tests/dbus-appinfo.c @@ -254,11 +254,14 @@ test_dbus_appinfo (void) const gchar *argv[] = { "myapp", NULL }; TestApplication *app; int status; + gchar *desktop_file = NULL; - appinfo = g_desktop_app_info_new_from_filename (g_test_build_filename (G_TEST_DIST, - "org.gtk.test.dbusappinfo.desktop", - NULL)); + desktop_file = g_test_build_filename (G_TEST_DIST, + "org.gtk.test.dbusappinfo.desktop", + NULL); + appinfo = g_desktop_app_info_new_from_filename (desktop_file); g_assert (appinfo != NULL); + g_free (desktop_file); app = g_object_new (test_application_get_type (), "application-id", "org.gtk.test.dbusappinfo", diff --git a/gio/tests/desktop-app-info.c b/gio/tests/desktop-app-info.c index 639b27e18..4871d85a5 100644 --- a/gio/tests/desktop-app-info.c +++ b/gio/tests/desktop-app-info.c @@ -93,6 +93,8 @@ test_delete (void) res = g_app_info_delete (info); g_assert (!res); } + + g_free (filename); } static void @@ -115,6 +117,7 @@ test_default (void) info = g_app_info_get_default_for_type ("application/x-test", FALSE); g_assert (info != NULL); g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2)); + g_object_unref (info); /* now try adding something, but not setting as default */ g_app_info_add_supports_type (info3, "application/x-test", &error); @@ -124,6 +127,7 @@ test_default (void) info = g_app_info_get_default_for_type ("application/x-test", FALSE); g_assert (info != NULL); g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2)); + g_object_unref (info); /* now remove info1 again */ g_app_info_remove_supports_type (info1, "application/x-test", &error); @@ -133,6 +137,7 @@ test_default (void) info = g_app_info_get_default_for_type ("application/x-test", FALSE); g_assert (info != NULL); g_assert_cmpstr (g_app_info_get_id (info), ==, g_app_info_get_id (info2)); + g_object_unref (info); /* now clean it all up */ g_app_info_reset_type_associations ("application/x-test"); @@ -146,6 +151,7 @@ test_default (void) g_object_unref (info1); g_object_unref (info2); + g_object_unref (info3); } static void @@ -324,6 +330,8 @@ cleanup_dir_recurse (GFile *parent, ret = TRUE; out: + g_clear_object (&enumerator); + return ret; } @@ -342,6 +350,7 @@ cleanup_subdirs (const char *base_dir) (void) cleanup_dir_recurse (file, file, &error); g_assert_no_error (error); g_object_unref (file); + g_object_unref (base); } static void diff --git a/gio/tests/file.c b/gio/tests/file.c index 9d5a6e8cd..d2f147419 100644 --- a/gio/tests/file.c +++ b/gio/tests/file.c @@ -913,6 +913,13 @@ get_size_from_du (const gchar *path, guint64 *size) gchar *result; gchar *endptr; GError *error = NULL; + gchar *du_path = NULL; + + /* If we can’t find du, don’t try and run the test. */ + du_path = g_find_program_in_path ("du"); + if (du_path == NULL) + return FALSE; + g_free (du_path); du = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE, &error, @@ -950,7 +957,7 @@ test_measure (void) path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL); file = g_file_new_for_path (path); - if (!g_find_program_in_path ("du") || !get_size_from_du (path, &size)) + if (!get_size_from_du (path, &size)) { g_test_message ("du not found or fail to run, skipping byte measurement"); size = 0; @@ -1052,8 +1059,7 @@ test_measure_async (void) path = g_test_build_filename (G_TEST_DIST, "desktop-files", NULL); file = g_file_new_for_path (path); - if (!g_find_program_in_path ("du") || - !get_size_from_du (path, &data->expected_bytes)) + if (!get_size_from_du (path, &data->expected_bytes)) { g_test_message ("du not found or fail to run, skipping byte measurement"); data->expected_bytes = 0; diff --git a/gio/tests/g-file-info-filesystem-readonly.c b/gio/tests/g-file-info-filesystem-readonly.c index c2b0aa518..123dcd8a0 100644 --- a/gio/tests/g-file-info-filesystem-readonly.c +++ b/gio/tests/g-file-info-filesystem-readonly.c @@ -45,6 +45,8 @@ test_filesystem_readonly (gconstpointer with_mount_monitor) { /* We need these because "mount --bind" requires root privileges */ g_test_skip ("'bindfs' and 'fusermount' commands are needed to run this test"); + g_free (fusermount); + g_free (bindfs); return; } diff --git a/gio/tests/gdbus-peer-object-manager.c b/gio/tests/gdbus-peer-object-manager.c index 933cc529d..676c9f080 100644 --- a/gio/tests/gdbus-peer-object-manager.c +++ b/gio/tests/gdbus-peer-object-manager.c @@ -258,6 +258,8 @@ setup (Test *test, g_assert (test->server); g_assert (test->client); + + g_object_unref (stream); } static void diff --git a/gio/tests/gdbus-peer.c b/gio/tests/gdbus-peer.c index 101c2a8bb..7f35baae6 100644 --- a/gio/tests/gdbus-peer.c +++ b/gio/tests/gdbus-peer.c @@ -875,6 +875,7 @@ test_peer (void) getuid ()); g_assert_cmpuint (g_credentials_get_unix_pid (credentials, NULL), ==, getpid ()); + g_object_unref (credentials); #else g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED); g_assert (credentials == NULL); @@ -1358,6 +1359,8 @@ test_nonce_tcp (void) g_main_loop_quit (service_loop); g_thread_join (service_thread); + + g_ptr_array_unref (data.current_connections); } static void @@ -1711,6 +1714,7 @@ codegen_test_peer (void) * change notifications anyway because those are done from an idle handler */ example_animal_call_poke_sync (animal2, TRUE, TRUE, NULL, &error); + g_clear_error (&error); g_object_unref (animal1); g_object_unref (animal2); diff --git a/gio/tests/resources.c b/gio/tests/resources.c index 8163aa141..5d2e27474 100644 --- a/gio/tests/resources.c +++ b/gio/tests/resources.c @@ -547,7 +547,8 @@ test_uri_query_info (void) GBytes *data; GFile *file; GFileInfo *info; - const char *content_type, *mime_type; + const char *content_type; + gchar *mime_type = NULL; const char *fs_type; gboolean readonly; @@ -573,6 +574,7 @@ test_uri_query_info (void) mime_type = g_content_type_get_mime_type (content_type); g_assert (mime_type); g_assert_cmpstr (mime_type, ==, "text/plain"); + g_free (mime_type); g_object_unref (info); diff --git a/gio/tests/simple-proxy.c b/gio/tests/simple-proxy.c index f1eb6af9b..ffc16eddd 100644 --- a/gio/tests/simple-proxy.c +++ b/gio/tests/simple-proxy.c @@ -77,6 +77,7 @@ test_uris (void) g_assert_cmpstr (error->message, ==, str); g_clear_error (&error); g_assert_null (proxies); + g_object_unref (result); g_object_unref (resolver); g_free (str); diff --git a/gio/tests/task.c b/gio/tests/task.c index 08d78e5ef..934262e40 100644 --- a/gio/tests/task.c +++ b/gio/tests/task.c @@ -1902,6 +1902,7 @@ legacy_error_callback (GObject *object, g_assert_error (error, G_IO_ERROR, G_IO_ERROR_FAILED); *result_out = -2; + g_clear_error (&error); } else { diff --git a/gio/tests/unix-streams.c b/gio/tests/unix-streams.c index dafaf66aa..67a90d83d 100644 --- a/gio/tests/unix-streams.c +++ b/gio/tests/unix-streams.c @@ -178,6 +178,7 @@ main_thread_read (GObject *source, GAsyncResult *res, gpointer user_data) if (g_cancellable_is_cancelled (main_cancel)) { do_main_cancel (out); + g_clear_error (&err); return; } @@ -214,6 +215,7 @@ main_thread_wrote (GObject *source, GAsyncResult *res, gpointer user_data) if (g_cancellable_is_cancelled (main_cancel)) { do_main_cancel (out); + g_clear_error (&err); return; } diff --git a/glib.supp b/glib.supp index 7a3fe6bc3..f64826b3c 100644 --- a/glib.supp +++ b/glib.supp @@ -51,6 +51,16 @@ fun:initialize_module_inlock_reentrant } +# One-time allocation from libc for getpwnam() results +{ + g-local-vfs-getpwnam + Memcheck:Leak + fun:malloc + ... + fun:getpwnam + fun:g_local_vfs_parse_name +} + { gobject-init-malloc Memcheck:Leak @@ -232,6 +242,18 @@ fun:_g_io_module_get_default } +# One-time getaddrinfo() configuration loading +{ + g-threaded-resolver-getaddrinfo-config + Memcheck:Leak + fun:malloc + ... + fun:__resolv_conf_allocate + ... + fun:getaddrinfo + fun:do_lookup_by_name +} + # memcheck checks that the third argument to ioctl() is a valid pointer, but # some ioctls use that argument as an integer { diff --git a/glib/tests/option-context.c b/glib/tests/option-context.c index 60d3bd313..34ebfaaf6 100644 --- a/glib/tests/option-context.c +++ b/glib/tests/option-context.c @@ -2550,6 +2550,7 @@ double_free (void) g_option_context_free (context); g_clear_error (&error); + g_strfreev (argv); } diff --git a/glib/tests/sequence.c b/glib/tests/sequence.c index f01738f7f..8e74d090a 100644 --- a/glib/tests/sequence.c +++ b/glib/tests/sequence.c @@ -1379,6 +1379,8 @@ test_empty (void) } g_assert_true (g_sequence_is_empty (seq)); + + g_sequence_free (seq); } int diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index 212291b57..f7568ce98 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -394,6 +394,8 @@ test_spawn_nonexistent (void) g_assert_cmpint (exit_status, ==, -1); g_ptr_array_free (argv, TRUE); + + g_clear_error (&error); } int diff --git a/gobject/tests/properties.c b/gobject/tests/properties.c index a1af3f8ba..0aa325a74 100644 --- a/gobject/tests/properties.c +++ b/gobject/tests/properties.c @@ -80,7 +80,10 @@ test_object_set_quux (TestObject *obj, static void test_object_finalize (GObject *gobject) { - g_free (((TestObject *) gobject)->baz); + TestObject *self = (TestObject *) gobject; + + g_free (self->baz); + g_free (self->quux); /* When the ref_count of an object is zero it is still * possible to notify the property, but it should do @@ -412,6 +415,9 @@ properties_testv_with_valid_properties (void) g_assert_cmpstr (g_value_get_string (&values_out[2]), ==, "pigs"); g_assert_cmpstr (g_value_get_string (&values_out[3]), ==, "fly"); + for (i = 0; i < G_N_ELEMENTS (values_out); i++) + g_value_unset (&values_out[i]); + /* Test newv2 && getv */ g_value_set_string (&(values_in[2]), "Elmo knows"); g_value_set_string (&(values_in[3]), "where you live"); @@ -425,12 +431,10 @@ properties_testv_with_valid_properties (void) g_assert_cmpstr (g_value_get_string (&values_out[2]), ==, "Elmo knows"); g_assert_cmpstr (g_value_get_string (&values_out[3]), ==, "where you live"); - - for (i = 0; i < 4; i++) - { - g_value_unset (&values_in[i]); - g_value_unset (&values_out[i]); - } + for (i = 0; i < G_N_ELEMENTS (values_in); i++) + g_value_unset (&values_in[i]); + for (i = 0; i < G_N_ELEMENTS (values_out); i++) + g_value_unset (&values_out[i]); g_object_unref (test_obj); } diff --git a/gobject/tests/reference.c b/gobject/tests/reference.c index e3f86315c..b05150e96 100644 --- a/gobject/tests/reference.c +++ b/gobject/tests/reference.c @@ -156,11 +156,14 @@ test_set (void) { GObject *o = NULL; GObject *tmp; + gpointer tmp_weak = NULL; g_assert (!g_set_object (&o, NULL)); g_assert (o == NULL); tmp = g_object_new (G_TYPE_OBJECT, NULL); + tmp_weak = tmp; + g_object_add_weak_pointer (tmp, &tmp_weak); g_assert_cmpint (tmp->ref_count, ==, 1); g_assert (g_set_object (&o, tmp)); @@ -174,10 +177,11 @@ test_set (void) g_assert (!g_set_object (&o, tmp)); g_assert (o == tmp); g_assert_cmpint (tmp->ref_count, ==, 1); + g_assert_nonnull (tmp_weak); g_assert (g_set_object (&o, NULL)); g_assert (o == NULL); - g_assert (!G_IS_OBJECT (tmp)); /* finalised */ + g_assert_null (tmp_weak); } static void @@ -185,11 +189,14 @@ test_set_function (void) { GObject *o = NULL; GObject *tmp; + gpointer tmp_weak = NULL; g_assert (!(g_set_object) (&o, NULL)); g_assert (o == NULL); tmp = g_object_new (G_TYPE_OBJECT, NULL); + tmp_weak = tmp; + g_object_add_weak_pointer (tmp, &tmp_weak); g_assert_cmpint (tmp->ref_count, ==, 1); g_assert ((g_set_object) (&o, tmp)); @@ -203,10 +210,11 @@ test_set_function (void) g_assert (!(g_set_object) (&o, tmp)); g_assert (o == tmp); g_assert_cmpint (tmp->ref_count, ==, 1); + g_assert_nonnull (tmp_weak); g_assert ((g_set_object) (&o, NULL)); g_assert (o == NULL); - g_assert (!G_IS_OBJECT (tmp)); /* finalised */ + g_assert_null (tmp_weak); } static void diff --git a/tests/refcount/objects.c b/tests/refcount/objects.c index 265276901..963766d00 100644 --- a/tests/refcount/objects.c +++ b/tests/refcount/objects.c @@ -155,6 +155,7 @@ main (int argc, char **argv) g_object_unref (test1); g_object_unref (test2); + g_array_unref (test_threads); g_print ("stopped\n");