fp-device: Use different pointers for device handlers

A Fp-device use an union to track the handle to the lower-level device, and
the value depends on the object type.

So in case of using a virtual device, the priv->usb_device location matches
the priv->virtual_env string location, and thus we'd end up unreffing a
string location as it was a GObject, while we'd leak the string.

To avoid such errors, instead of just checking the device type when we
finalize the device, let's just use different pointers to avoid other
possible clashes.
This commit is contained in:
Marco Trevisan (Treviño) 2019-12-05 13:16:11 +01:00
parent 107fdfde32
commit ff0107fc0a

View file

@ -50,11 +50,8 @@ typedef struct
{
FpDeviceType type;
union
{
GUsbDevice *usb_device;
const gchar *virtual_env;
};
gboolean is_open;
@ -382,7 +379,9 @@ fp_device_finalize (GObject *object)
g_clear_pointer (&priv->device_id, g_free);
g_clear_pointer (&priv->device_name, g_free);
g_clear_object (&priv->usb_device);
g_clear_pointer (&priv->virtual_env, g_free);
G_OBJECT_CLASS (fp_device_parent_class)->finalize (object);
}