From d66e9470d806fdcf67094c17688b101cff872548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 22 Jun 2023 22:43:27 +0200 Subject: [PATCH] context: Ensure that context won't include a removed device at signal time If a device has been removed from context, at that point we it should not be returned by fp_context_get_devices(). --- libfprint/fp-context.c | 4 +++- tests/test-fp-context.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libfprint/fp-context.c b/libfprint/fp-context.c index c5c228b7..08bfd4c7 100644 --- a/libfprint/fp-context.c +++ b/libfprint/fp-context.c @@ -96,8 +96,10 @@ remove_device (FpContext *context, g_return_if_fail (g_ptr_array_find (priv->devices, device, &idx)); - g_signal_emit (context, signals[DEVICE_REMOVED_SIGNAL], 0, device); + g_object_ref (device); g_ptr_array_remove_index_fast (priv->devices, idx); + g_signal_emit (context, signals[DEVICE_REMOVED_SIGNAL], 0, device); + g_clear_object (&device); } static void diff --git a/tests/test-fp-context.c b/tests/test-fp-context.c index da33b690..15bb469f 100644 --- a/tests/test-fp-context.c +++ b/tests/test-fp-context.c @@ -115,6 +115,8 @@ context_device_removed_cb (FpContext *ctx, FpDevice *device, FptContext *tctx) /* "device-removed" on context is always after "removed" on device */ g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB); tctx->user_data = GINT_TO_POINTER (CTX_DEVICE_REMOVED_CB); + + g_assert_false (g_ptr_array_find (fp_context_get_devices (tctx->fp_context), device, NULL)); } static void