[fprint] [PATCH] core: keep a reference on device and free dev list

Marco Trevisan (TreviƱo) mail at 3v1n0.net
Fri Feb 16 01:55:58 UTC 2018


Fixes the memory leak on devs. I think it's
better to keep a reference on the udev too,
but this could be changed.

---
 libfprint/core.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libfprint/core.c b/libfprint/core.c
index 81b972e..1c48bf1 100644
--- a/libfprint/core.c
+++ b/libfprint/core.c
@@ -524,7 +524,7 @@ static struct fp_dscv_dev
*discover_dev(libusb_device *udev)
  	ddev = g_malloc0(sizeof(*ddev));
 	ddev->drv = drv;
-	ddev->udev = udev;
+	ddev->udev = libusb_ref_device(udev);
 	ddev->driver_data = usb_id->driver_data;
 	ddev->devtype = devtype;
 	return ddev;
@@ -580,6 +580,7 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void)
 	}
 	list[dscv_count] = NULL; /* NULL-terminate */
 +	libusb_free_device_list(devs, 1);
 	g_slist_free(tmplist);
 	return list;
 }
@@ -597,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.7.4



More information about the fprint mailing list