[sane-devel] Trouble with sanei_usb change (commit ef5820ce6238469b9946b37e21ec5355edfa520a)
Stef
stef.dev at free.fr
Thu Feb 28 06:28:55 UTC 2013
On 27/02/2013 22:10, Stef wrote:
> On 27/02/2013 21:59, Stef wrote:
>> Hello,
>>
>> the ef5820ce6238469b9946b37e21ec5355edfa520a commit is causing me
>> troubles.
>> Should we free devname on close ? We can open/close several times the
>> same device, so I think freeing in sanei_usb_close is problematic.
>> Reverting this change restored functionality to my backend.
>>
>> Regards,
>> Stef
>>
> After further looking at this issue, I think we should add a
> sanei_usb_exit() function to take care of allocated resources ins
> sanei_usb_init(). Another case we can free memory is when the device
> is marked missing (missing field reaching 0).
>
> Regards,
> Stef
>
>
Hello,
regarding the memory leak, the following patch takes care of the
case where memory is leaked on device that get unplugged or powered off.
About the few bytes left when a backend exits, what is really
needed is a sanei_usb_exit function. This function would free allocated
resources when the last user of sanei_usb_init() calls it.
diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c
index cdcca3f..a9696c4 100644
--- a/sanei/sanei_usb.c
+++ b/sanei/sanei_usb.c
@@ -364,8 +364,15 @@ store_device (device_list_type device)
pos = i;
}
+ /* reuse slot of a device now missing */
if(pos > -1){
DBG (3, "store_device: overwrite dn %d with %s\n", pos,
device.devname);
+ /* we reuse the slot used by a now missing device
+ * so we free the allocated memory for the missing one */
+ if (devices[pos].devname) {
+ free(devices[pos].devname);
+ devices[pos].devname = NULL;
+ }
}
else{
if(device_number >= MAX_DEVICES){
@@ -2039,10 +2046,6 @@ sanei_usb_close (SANE_Int dn)
DBG (1, "sanei_usb_close: libusb support missing\n");
#endif
devices[dn].open = SANE_FALSE;
- if (devices[dn].devname) {
- free(devices[dn].devname);
- devices[dn].devname = NULL;
- }
return;
}
More information about the sane-devel
mailing list