diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 6dd337b201..efbe6c9ae5 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -921,33 +921,26 @@ _nmtst_main_loop_run_timeout (gpointer user_data) { GMainLoop **p_loop = user_data; - g_assert (p_loop); - g_assert (*p_loop); - - g_main_loop_quit (*p_loop); - *p_loop = NULL; - + g_assert (p_loop && *p_loop); + g_main_loop_quit (g_steal_pointer (p_loop)); return G_SOURCE_REMOVE; } static inline gboolean nmtst_main_loop_run (GMainLoop *loop, guint timeout_ms) { - GSource *source = NULL; - guint id = 0; + nm_auto_unref_gsource GSource *source = NULL; GMainLoop *loopx = loop; if (timeout_ms > 0) { source = g_timeout_source_new (timeout_ms); g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL); - id = g_source_attach (source, g_main_loop_get_context (loop)); - g_assert (id); - g_source_unref (source); + g_source_attach (source, g_main_loop_get_context (loop)); } g_main_loop_run (loop); - if (source && loopx) + if (source) g_source_destroy (source); /* if the timeout was reached, return FALSE. */