From a291d17f26edc9728db021d941138d50a824c971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 24 Jan 2021 02:03:20 +0100 Subject: [PATCH] virtual-device: Properly cleanup the virtual devices data Ensure we call the parent finalize function and cleanup local data --- libfprint/drivers/virtual-device-storage.c | 13 +++++++++++++ libfprint/drivers/virtual-device.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/libfprint/drivers/virtual-device-storage.c b/libfprint/drivers/virtual-device-storage.c index 355f495..c948a6b 100644 --- a/libfprint/drivers/virtual-device-storage.c +++ b/libfprint/drivers/virtual-device-storage.c @@ -167,6 +167,16 @@ fpi_device_virtual_device_storage_init (FpDeviceVirtualDeviceStorage *self) NULL); } +static void +fpi_device_virtual_device_storage_finalize (GObject *object) +{ + FpDeviceVirtualDevice *vdev = FP_DEVICE_VIRTUAL_DEVICE (object); + + G_DEBUG_HERE (); + g_clear_pointer (&vdev->prints_storage, g_hash_table_destroy); + G_OBJECT_CLASS (fpi_device_virtual_device_storage_parent_class)->finalize (object); +} + static const FpIdEntry driver_ids[] = { { .virtual_envvar = "FP_VIRTUAL_DEVICE_STORAGE" }, { .virtual_envvar = "FP_VIRTUAL_DEVICE_IDENT" }, @@ -177,6 +187,9 @@ static void fpi_device_virtual_device_storage_class_init (FpDeviceVirtualDeviceStorageClass *klass) { FpDeviceClass *dev_class = FP_DEVICE_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = fpi_device_virtual_device_storage_finalize; dev_class->id = FP_COMPONENT; dev_class->full_name = "Virtual device with storage and identification for debugging"; diff --git a/libfprint/drivers/virtual-device.c b/libfprint/drivers/virtual-device.c index 5f193d6..03453b0 100644 --- a/libfprint/drivers/virtual-device.c +++ b/libfprint/drivers/virtual-device.c @@ -419,7 +419,11 @@ dev_deinit (FpDevice *dev) static void fpi_device_virtual_device_finalize (GObject *object) { + FpDeviceVirtualDevice *self = FP_DEVICE_VIRTUAL_DEVICE (object); + G_DEBUG_HERE (); + g_clear_pointer (&self->pending_commands, g_ptr_array_unref); + G_OBJECT_CLASS (fpi_device_virtual_device_parent_class)->finalize (object); } static void