From 58ba9b02ed4da8c7ee24d8024a85582731f8ec68 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sat, 10 Mar 2018 18:14:42 +0000 Subject: [PATCH] lib: Fix memory leak patch in device discovery libusb_free_device_list() needs to be called on the list of USB devices obtained through libusb_get_device_list() or the list and its elements will be leaked. https://bugs.freedesktop.org/show_bug.cgi?id=105427 --- libfprint/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libfprint/core.c b/libfprint/core.c index 522213e..97aa5fd 100644 --- a/libfprint/core.c +++ b/libfprint/core.c @@ -561,9 +561,13 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void) struct fp_dscv_dev *ddev = discover_dev(udev); if (!ddev) continue; + /* discover_dev() doesn't hold a reference to the udev, + * so increase the reference for ddev to hold this ref */ + libusb_ref_device(udev); tmplist = g_slist_prepend(tmplist, (gpointer) ddev); dscv_count++; } + libusb_free_device_list(devs, 1); /* Convert our temporary GSList into a standard NULL-terminated pointer * array. */ @@ -594,8 +598,10 @@ API_EXPORTED void fp_dscv_devs_free(struct fp_dscv_dev **devs) if (!devs) return; - for (i = 0; devs[i]; i++) + for (i = 0; devs[i]; i++) { + libusb_unref_device(devs[i]->udev); g_free(devs[i]); + } g_free(devs); } -- 2.14.3