libfprint/SOURCES/0174-device-Better-define-ownership-passing-for-results.patch

196 lines
7.8 KiB
Diff
Raw Normal View History

2020-04-23 23:55:43 +00:00
From e45ebf1af2a29f861a9aec367981492688692a72 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Mon, 13 Jan 2020 13:25:48 +0100
Subject: [PATCH 174/181] device: Better define ownership passing for results
Some things were odd with regard to the ownership of passed objects. Try
to make things sane overall, in particular with the possible floating
FpPrint reference.
---
libfprint/fpi-device.c | 20 ++++++++++++++++----
libfprint/fpi-image-device.c | 2 +-
tests/test-fpi-device.c | 24 ++++++++++++------------
3 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/libfprint/fpi-device.c b/libfprint/fpi-device.c
index 51dbee1..8b2ef9d 100644
--- a/libfprint/fpi-device.c
+++ b/libfprint/fpi-device.c
@@ -908,7 +908,7 @@ fpi_device_enroll_complete (FpDevice *device, FpPrint *print, GError *error)
* fpi_device_verify_complete:
* @device: The #FpDevice
* @result: The #FpiMatchResult of the operation
- * @print: The scanned #FpPrint
+ * @print: (transfer floating) The scanned #FpPrint
* @error: A #GError if result is %FPI_MATCH_ERROR
*
* Finish an ongoing verify operation. The returned print should be
@@ -929,6 +929,9 @@ fpi_device_verify_complete (FpDevice *device,
clear_device_cancel_action (device);
+ if (print)
+ g_object_ref_sink (print);
+
g_object_set_data_full (G_OBJECT (priv->current_task),
"print",
print,
@@ -963,8 +966,8 @@ fpi_device_verify_complete (FpDevice *device,
/**
* fpi_device_identify_complete:
* @device: The #FpDevice
- * @match: The matching #FpPrint from the passed gallery, or %NULL if none matched
- * @print: The scanned #FpPrint, may be %NULL
+ * @match: (transfer none): The matching #FpPrint from the passed gallery, or %NULL if none matched
+ * @print: (transfer floating): The scanned #FpPrint, may be %NULL
* @error: The #GError or %NULL on success
*
* Finish an ongoing identify operation. The match that was identified is
@@ -986,6 +989,12 @@ fpi_device_identify_complete (FpDevice *device,
clear_device_cancel_action (device);
+ if (match)
+ g_object_ref (match);
+
+ if (print)
+ g_object_ref_sink (print);
+
g_object_set_data_full (G_OBJECT (priv->current_task),
"print",
print,
@@ -1134,7 +1143,7 @@ fpi_device_list_complete (FpDevice *device,
* fpi_device_enroll_progress:
* @device: The #FpDevice
* @completed_stages: The number of stages that are completed at this point
- * @print: (transfer full): The #FpPrint for the newly completed stage or %NULL on failure
+ * @print: (transfer floating): The #FpPrint for the newly completed stage or %NULL on failure
* @error: (transfer full): The #GError or %NULL on success
*
* Notify about the progress of the enroll operation. This is important for UI interaction.
@@ -1155,6 +1164,9 @@ fpi_device_enroll_progress (FpDevice *device,
g_debug ("Device reported enroll progress, reported %i of %i have been completed", completed_stages, priv->nr_enroll_stages);
+ if (print)
+ g_object_ref_sink (print);
+
if (error && print)
{
g_warning ("Driver passed an error and also provided a print, returning error!");
diff --git a/libfprint/fpi-image-device.c b/libfprint/fpi-image-device.c
index efdbb53..f962b8a 100644
--- a/libfprint/fpi-image-device.c
+++ b/libfprint/fpi-image-device.c
@@ -226,7 +226,7 @@ fpi_image_device_minutiae_detected (GObject *source_object, GAsyncResult *res, g
if (fpi_print_bz3_match (template, print, priv->bz3_threshold, &error) == FPI_MATCH_SUCCESS)
{
- result = g_object_ref (template);
+ result = template;
break;
}
}
diff --git a/tests/test-fpi-device.c b/tests/test-fpi-device.c
index 3fa800c..3d1e81c 100644
--- a/tests/test-fpi-device.c
+++ b/tests/test-fpi-device.c
@@ -548,10 +548,10 @@ test_driver_verify (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
- g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
+ g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
+ g_autoptr(FpPrint) out_print = NULL;
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *out_print = NULL;
gboolean match;
fake_dev->ret_result = FPI_MATCH_SUCCESS;
@@ -570,10 +570,10 @@ test_driver_verify_fail (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
- g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
+ g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
+ g_autoptr(FpPrint) out_print = NULL;
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *out_print = NULL;
gboolean match;
fake_dev->ret_result = FPI_MATCH_FAIL;
@@ -591,10 +591,10 @@ test_driver_verify_error (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
- g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
+ g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
+ g_autoptr(FpPrint) out_print = NULL;
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *out_print = NULL;
gboolean match;
fake_dev->ret_result = FPI_MATCH_ERROR;
@@ -641,16 +641,16 @@ test_driver_identify (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
+ g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *matched_print;
FpPrint *expected_matched;
unsigned int i;
for (i = 0; i < 500; ++i)
- g_ptr_array_add (prints, fp_print_new (device));
+ g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
@@ -673,15 +673,15 @@ test_driver_identify_fail (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
+ g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *matched_print;
unsigned int i;
for (i = 0; i < 500; ++i)
- g_ptr_array_add (prints, fp_print_new (device));
+ g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
g_assert_true (fp_device_supports_identify (device));
@@ -700,16 +700,16 @@ test_driver_identify_error (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
+ g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
- FpPrint *matched_print;
FpPrint *expected_matched;
unsigned int i;
for (i = 0; i < 500; ++i)
- g_ptr_array_add (prints, fp_print_new (device));
+ g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
--
2.24.1