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.
This commit is contained in:
parent
43a8c909bf
commit
eeddd8c7bc
3 changed files with 11 additions and 24 deletions
|
@ -131,14 +131,12 @@ usb_device_added_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx)
|
||||||
for (i = 0; i < priv->drivers->len; i++)
|
for (i = 0; i < priv->drivers->len; i++)
|
||||||
{
|
{
|
||||||
GType driver = g_array_index (priv->drivers, GType, 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;
|
const FpIdEntry *entry;
|
||||||
|
|
||||||
if (cls->type != FP_DEVICE_TYPE_USB)
|
if (cls->type != FP_DEVICE_TYPE_USB)
|
||||||
{
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
for (entry = cls->id_table; entry->pid; entry++)
|
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_driver = driver;
|
||||||
found_entry = entry;
|
found_entry = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_driver == G_TYPE_NONE)
|
if (found_driver == G_TYPE_NONE)
|
||||||
|
@ -355,7 +351,8 @@ fp_context_enumerate (FpContext *context)
|
||||||
for (i = 0; i < priv->drivers->len; i++)
|
for (i = 0; i < priv->drivers->len; i++)
|
||||||
{
|
{
|
||||||
GType driver = g_array_index (priv->drivers, GType, 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;
|
const FpIdEntry *entry;
|
||||||
|
|
||||||
if (cls->type != FP_DEVICE_TYPE_VIRTUAL)
|
if (cls->type != FP_DEVICE_TYPE_VIRTUAL)
|
||||||
|
@ -381,8 +378,6 @@ fp_context_enumerate (FpContext *context)
|
||||||
NULL);
|
NULL);
|
||||||
g_debug ("created");
|
g_debug ("created");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (priv->pending_devices)
|
while (priv->pending_devices)
|
||||||
|
|
|
@ -38,14 +38,12 @@ insert_drivers (GList *list)
|
||||||
for (i = 0; i < drivers->len; i++)
|
for (i = 0; i < drivers->len; i++)
|
||||||
{
|
{
|
||||||
GType driver = g_array_index (drivers, GType, 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;
|
const FpIdEntry *entry;
|
||||||
|
|
||||||
if (cls->type != FP_DEVICE_TYPE_USB)
|
if (cls->type != FP_DEVICE_TYPE_USB)
|
||||||
{
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
for (entry = cls->id_table; entry->vid; entry++)
|
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));
|
list = g_list_prepend (list, g_strdup_printf ("%s | %s\n", key, cls->full_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -104,17 +104,13 @@ main (int argc, char **argv)
|
||||||
for (i = 0; i < drivers->len; i++)
|
for (i = 0; i < drivers->len; i++)
|
||||||
{
|
{
|
||||||
GType driver = g_array_index (drivers, GType, 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)
|
if (cls->type != FP_DEVICE_TYPE_USB)
|
||||||
{
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
print_driver (cls);
|
print_driver (cls);
|
||||||
|
|
||||||
g_type_class_unref (cls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print_driver (&whitelist);
|
print_driver (&whitelist);
|
||||||
|
|
Loading…
Reference in a new issue