[sane-devel] sanei_usb_exit()

Ralph Little skelband at gmail.com
Fri Dec 27 19:51:36 GMT 2024


Hi,
I'm looking for some opinions on sanei_usb as to how best to clean up after
it.

Backends that use sanei_usb call sanei_usb_init() to get things going
before using the subsystem functions. However, it is not obvious who should
call sanei_usb_exit().

sane_usb_init() is a NOP for all but the first invocation. So all sanei_usb
users can and should call it before doing USB work. The same is true of
sanei_usb_exit(). However, any of the backends could do sanei_usb cleanup
work in their sane_exit() function, although they should probably make
sure that it is all gone during the last sane_close(). Any backend that
previously called sanei_usb_exit() will make any USB cleanup work fail for
subsequent backends' sane_exit().

We have a mixed bag at the moment. Some backends call sanei_usb_exit() in
their exit functions. However, many don't. We could remove all the
sanei_usb_exit() functions from the backends and add it to the dll.c exit
function to be executed after all backends have been unloaded. However,
this feels bad because the init() and exit() functions are called at
different levels in different contexts. A backend DLL could also be called
without the aid of the dll helper layer so it would not properly clean up
after itself.

The main issue it seems to me is that each backend doesn't have its own
sanei_usb context and sanei_usb_init() doesn't "stack".

This has come about from recent testing that came from a user detecting
leakage of resources here:
https://gitlab.com/sane-project/backends/-/issues/788

Opinions sought.

Cheers,
Ralph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20241227/066ab1a3/attachment.htm>


More information about the sane-devel mailing list