tests: Explicitly remove a timeout handler in gapplication test

Otherwise if, for whatever reason, the `app` loses its D-Bus name,
`g_application_quit()` is called from `name_was_lost()` before it’s
called from `quit_already()`, and then `quit_already()` does an invalid
read on `app`.

If the name was not meant to be lost at this point in the test, the
subsequent `g_assert_false (name_lost)` will catch that, so this change
shouldn’t cause the test to pass unnecessarily.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2023-01-24 11:25:34 +00:00
parent 90af624d5b
commit 73205b8bbd

View File

@ -1159,6 +1159,7 @@ test_replace (gconstpointer data)
gboolean name_lost = FALSE;
TestReplaceData data;
GTestDBus *bus;
guint timeout_id = 0;
data.allow_replacement = allow;
data.subprocess = NULL;
@ -1173,7 +1174,7 @@ test_replace (gconstpointer data)
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
if (!allow)
g_timeout_add_seconds (1, quit_already, app);
timeout_id = g_timeout_add_seconds (1, quit_already, app);
g_application_run (app, G_N_ELEMENTS (argv) - 1, argv);
@ -1183,6 +1184,7 @@ test_replace (gconstpointer data)
else
g_assert_false (name_lost);
g_clear_handle_id (&timeout_id, g_source_remove);
g_object_unref (app);
g_free (binpath);