Bug 105427 - Memory leak in lib: core.c
Summary: Memory leak in lib: core.c
Status: RESOLVED FIXED
Alias: None
Product: libfprint
Classification: Unclassified
Component: libfprint (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: libfprint-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-10 09:14 UTC by Mark Harfouche
Modified: 2018-03-11 12:52 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
memory patch leka (1.08 KB, patch)
2018-03-10 09:14 UTC, Mark Harfouche
Details | Splinter Review
Memory leak patch in lib (1.18 KB, patch)
2018-03-10 18:04 UTC, Mark Harfouche
Details | Splinter Review
Memory leak patch in lib (1.97 KB, patch)
2018-03-10 18:14 UTC, Mark Harfouche
Details | Splinter Review
lib: Fix memory leak patch in device discovery (1.38 KB, patch)
2018-03-11 12:45 UTC, Bastien Nocera
Details | Splinter Review
examples: Fix memory leaked by device discovery (696 bytes, patch)
2018-03-11 12:46 UTC, Bastien Nocera
Details | Splinter Review

Description Mark Harfouche 2018-03-10 09:14:40 UTC
Created attachment 137959 [details] [review]
memory patch leka

I ran img_capture with valgrind to find memory leaks in my driver.

I ended up finding one in core.

Here is the patch for it.
Comment 1 Mark Harfouche 2018-03-10 09:25:30 UTC
Note, these changes are included in #99462
https://bugs.freedesktop.org/show_bug.cgi?id=99462

So if you end up merging 99462 (which I think you should), then this isn't necessary.
Comment 2 Bastien Nocera 2018-03-10 17:13:56 UTC
Comment on attachment 137959 [details] [review]
memory patch leka

Review of attachment 137959 [details] [review]:
-----------------------------------------------------------------

> memory leak

Please prefix with "lib: " and explain where the memory leak happens, and what is being leaked.

::: libfprint/core.c
@@ +564,4 @@
>  		struct fp_dscv_dev *ddev = discover_dev(udev);
>  		if (!ddev)
>  			continue;
> +    libusb_ref_device(udev);

Please fix the indentation to match the existing one.
Comment 3 Mark Harfouche 2018-03-10 18:04:45 UTC
Created attachment 137968 [details] [review]
Memory leak patch in lib

Fixed the indentation to follow the coding style
Comment 4 Mark Harfouche 2018-03-10 18:06:31 UTC
Comment on attachment 137968 [details] [review]
Memory leak patch in lib

Incomplete patch
Comment 5 Mark Harfouche 2018-03-10 18:14:42 UTC
Created attachment 137969 [details] [review]
Memory leak patch in lib

the library needs to call 	

libusb_free_device_list(devs, 1);

after 

libusb_get_device_list

To do so safely, I think you have to increment the reference to the device you want to use first, then just decrement the reference too the whole list.

In finding this bug, I also found a small bug in `img_capture` but that one isn't as important since it isn't part of the library.
Comment 6 Bastien Nocera 2018-03-11 12:45:40 UTC
Created attachment 137986 [details] [review]
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.
Comment 7 Bastien Nocera 2018-03-11 12:46:17 UTC
Created attachment 137988 [details] [review]
examples: Fix memory leaked by device discovery
Comment 8 Bastien Nocera 2018-03-11 12:48:10 UTC
Comment on attachment 137969 [details] [review]
Memory leak patch in lib

In the future, please try to provide git-formatted patches, and remove white space changes using "git checkout -p" before committing. The patches should also be split into individual cohesive commits as much as possible.

I've done all this for the 2 changes you provided.
Comment 9 Bastien Nocera 2018-03-11 12:52:27 UTC
Attachment 137986 [details] pushed as 58ba9b0 - lib: Fix memory leak patch in device discovery
Attachment 137988 [details] pushed as 7ff667f - examples: Fix memory leaked by device discovery


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.