From 187bed76f4dd33329729dc59788701b96ddaf48b Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 31 Aug 2023 15:21:48 -0700 Subject: [PATCH] libsysprof: avoid await() on non-fiber That is fine to do when the futures are finished, but in this case one might still be in-flight. Also, wait for all futures to complete before processing them. Use a finally() block so we can check even if there are errors. --- src/libsysprof/sysprof-linux-instrument.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libsysprof/sysprof-linux-instrument.c b/src/libsysprof/sysprof-linux-instrument.c index 2d279685..da21ef0c 100644 --- a/src/libsysprof/sysprof-linux-instrument.c +++ b/src/libsysprof/sysprof-linux-instrument.c @@ -339,16 +339,17 @@ process_started_cb (DexFuture *completed, for (guint i = 0; i < size; i++) { - DexFuture *future = dex_future_set_get_future_at (DEX_FUTURE_SET (completed), i); g_autoptr(GError) error = NULL; - g_autoptr(GVariant) variant = dex_await_variant (dex_ref (future), &error); + const GValue *value = NULL; + GVariant *variant = NULL; const char *path = g_ptr_array_index (state->paths, i); const char *bytestring = NULL; - if (error != NULL) + if (!(value = dex_future_set_get_value_at (DEX_FUTURE_SET (completed), i, &error))) continue; - if (variant == NULL || !g_variant_is_of_type (variant, G_VARIANT_TYPE ("(ay)"))) + if (!(variant = g_value_get_variant (value)) || + !g_variant_is_of_type (variant, G_VARIANT_TYPE ("(ay)"))) g_return_val_if_reached (NULL); g_variant_get (variant, "(^&ay)", &bytestring); @@ -442,10 +443,10 @@ sysprof_linux_instrument_process_started (SysprofInstrument *instrument, g_ptr_array_add (state->paths, g_steal_pointer (&mountinfo_path)); g_ptr_array_add (state->paths, g_steal_pointer (&flatpak_info_path)); - return dex_future_then (dex_future_any (mountinfo, flatpak_info, NULL), - process_started_cb, - state, - process_started_free); + return dex_future_finally (dex_future_all (mountinfo, flatpak_info, NULL), + process_started_cb, + state, + process_started_free); } static void