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