[Spice-devel] [PATCH spice-gtk 2/2] usb-device-manager: Fix reference counting getting devices

Frediano Ziglio fziglio at redhat.com
Thu Aug 1 09:52:22 UTC 2019


spice_usb_device_manager_device_to_bdev increments usb device
counter. The function is just used to check for filter but
than the counter is not decremented causing the object to be
leaked later (or invalid reference counter anyway).
Decrement the counter in any case.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 src/usb-device-manager.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index a035683d..0a04b119 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -1012,8 +1012,12 @@ GPtrArray* spice_usb_device_manager_get_devices_with_filter(
         if (rules) {
             SpiceUsbBackendDevice *bdev =
                 spice_usb_device_manager_device_to_bdev(self, device);
-            if (spice_usb_backend_device_check_filter(bdev, rules, count) != 0)
+            gboolean filter_ok =
+                (spice_usb_backend_device_check_filter(bdev, rules, count) == 0);
+            spice_usb_backend_device_unref(bdev);
+            if (!filter_ok) {
                 continue;
+            }
         }
         g_ptr_array_add(devices_copy, spice_usb_device_ref(device));
     }
-- 
2.20.1



More information about the Spice-devel mailing list