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

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