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

Submitted by Frediano Ziglio on Aug. 1, 2019, 9:52 a.m.

Details

Message ID 20190801095222.17475-2-fziglio@redhat.com
State Accepted
Commit 87333253cd6bac921e9b67d5c60f38a44396a8c8
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Aug. 1, 2019, 9:52 a.m.
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@redhat.com>
---
 src/usb-device-manager.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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));
     }