Blame SOURCES/0114-fp-context-tools-Use-auto-ptr-to-handle-GTypeClass-o.patch

73b847
From 7eb6eba6730f0636f39b5b248b8351bbfc6e6143 Mon Sep 17 00:00:00 2001
73b847
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
73b847
Date: Fri, 13 Dec 2019 20:40:41 +0100
73b847
Subject: [PATCH 114/181] fp-context, tools: Use auto-ptr to handle GTypeClass
73b847
 ownership
73b847
73b847
This also fixes a small leak we might have if reffing a type that was not a
73b847
virtual one.
73b847
---
73b847
 libfprint/fp-context.c                    | 15 +++++----------
73b847
 libfprint/fprint-list-supported-devices.c | 10 +++-------
73b847
 libfprint/fprint-list-udev-rules.c        | 10 +++-------
73b847
 3 files changed, 11 insertions(+), 24 deletions(-)
73b847
73b847
diff --git a/libfprint/fp-context.c b/libfprint/fp-context.c
73b847
index 6764241..f64968d 100644
73b847
--- a/libfprint/fp-context.c
73b847
+++ b/libfprint/fp-context.c
73b847
@@ -131,14 +131,12 @@ usb_device_added_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx)
73b847
   for (i = 0; i < priv->drivers->len; i++)
73b847
     {
73b847
       GType driver = g_array_index (priv->drivers, GType, i);
73b847
-      FpDeviceClass *cls = FP_DEVICE_CLASS (g_type_class_ref (driver));
73b847
+      g_autoptr(GTypeClass) type_class = g_type_class_ref (driver);
73b847
+      FpDeviceClass *cls = FP_DEVICE_CLASS (type_class);
73b847
       const FpIdEntry *entry;
73b847
 
73b847
       if (cls->type != FP_DEVICE_TYPE_USB)
73b847
-        {
73b847
-          g_type_class_unref (cls);
73b847
-          continue;
73b847
-        }
73b847
+        continue;
73b847
 
73b847
       for (entry = cls->id_table; entry->pid; entry++)
73b847
         {
73b847
@@ -158,8 +156,6 @@ usb_device_added_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx)
73b847
           found_driver = driver;
73b847
           found_entry = entry;
73b847
         }
73b847
-
73b847
-      g_type_class_unref (cls);
73b847
     }
73b847
 
73b847
   if (found_driver == G_TYPE_NONE)
73b847
@@ -355,7 +351,8 @@ fp_context_enumerate (FpContext *context)
73b847
   for (i = 0; i < priv->drivers->len; i++)
73b847
     {
73b847
       GType driver = g_array_index (priv->drivers, GType, i);
73b847
-      FpDeviceClass *cls = FP_DEVICE_CLASS (g_type_class_ref (driver));
73b847
+      g_autoptr(GTypeClass) type_class = g_type_class_ref (driver);
73b847
+      FpDeviceClass *cls = FP_DEVICE_CLASS (type_class);
73b847
       const FpIdEntry *entry;
73b847
 
73b847
       if (cls->type != FP_DEVICE_TYPE_VIRTUAL)
73b847
@@ -381,8 +378,6 @@ fp_context_enumerate (FpContext *context)
73b847
                                       NULL);
73b847
           g_debug ("created");
73b847
         }
73b847
-
73b847
-      g_type_class_unref (cls);
73b847
     }
73b847
 
73b847
   while (priv->pending_devices)
73b847
diff --git a/libfprint/fprint-list-supported-devices.c b/libfprint/fprint-list-supported-devices.c
73b847
index 55da252..cb2803f 100644
73b847
--- a/libfprint/fprint-list-supported-devices.c
73b847
+++ b/libfprint/fprint-list-supported-devices.c
73b847
@@ -38,14 +38,12 @@ insert_drivers (GList *list)
73b847
   for (i = 0; i < drivers->len; i++)
73b847
     {
73b847
       GType driver = g_array_index (drivers, GType, i);
73b847
-      FpDeviceClass *cls = FP_DEVICE_CLASS (g_type_class_ref (driver));
73b847
+      g_autoptr(GTypeClass) type_class = g_type_class_ref (driver);
73b847
+      FpDeviceClass *cls = FP_DEVICE_CLASS (type_class);
73b847
       const FpIdEntry *entry;
73b847
 
73b847
       if (cls->type != FP_DEVICE_TYPE_USB)
73b847
-        {
73b847
-          g_type_class_unref (cls);
73b847
-          continue;
73b847
-        }
73b847
+        continue;
73b847
 
73b847
       for (entry = cls->id_table; entry->vid; entry++)
73b847
         {
73b847
@@ -63,8 +61,6 @@ insert_drivers (GList *list)
73b847
 
73b847
           list = g_list_prepend (list, g_strdup_printf ("%s | %s\n", key, cls->full_name));
73b847
         }
73b847
-
73b847
-      g_type_class_unref (cls);
73b847
     }
73b847
 
73b847
   return list;
73b847
diff --git a/libfprint/fprint-list-udev-rules.c b/libfprint/fprint-list-udev-rules.c
73b847
index 335c37b..ac50797 100644
73b847
--- a/libfprint/fprint-list-udev-rules.c
73b847
+++ b/libfprint/fprint-list-udev-rules.c
73b847
@@ -104,17 +104,13 @@ main (int argc, char **argv)
73b847
   for (i = 0; i < drivers->len; i++)
73b847
     {
73b847
       GType driver = g_array_index (drivers, GType, i);
73b847
-      FpDeviceClass *cls = FP_DEVICE_CLASS (g_type_class_ref (driver));
73b847
+      g_autoptr(GTypeClass) type_class = g_type_class_ref (driver);
73b847
+      FpDeviceClass *cls = FP_DEVICE_CLASS (type_class);
73b847
 
73b847
       if (cls->type != FP_DEVICE_TYPE_USB)
73b847
-        {
73b847
-          g_type_class_unref (cls);
73b847
-          continue;
73b847
-        }
73b847
+        continue;
73b847
 
73b847
       print_driver (cls);
73b847
-
73b847
-      g_type_class_unref (cls);
73b847
     }
73b847
 
73b847
   print_driver (&whitelist);
73b847
-- 
73b847
2.24.1
73b847