Hello Nathan,
On Sunday, 26. July 2009 16:21:02 Nathan Fraser wrote:
> In some circumstances it is possible to send an invalid usb_dev
> pointer through to libusb after some errors or after an explicit
> close request. Result will be segfault or subtle corruption.
> This patch replaces all calls to usb_close with an internal wrapper
> that sets the usb handle to NULL after the usb_close, and refuses
> to call close on a NULL handle. Comments and/or discussion very welcome!
Thanks for your patch, I like the idea. Comments below.
> +/* internal usb_close wrapper -> sets usb dev handle to NULL */
> +int usb_close_intl (struct ftdi_context *ftdi)
> +{
> + int ret = 0;
> +
> + if (ftdi->usb_dev != NULL)
> + {
> + ret = usb_close (ftdi->usb_dev);
> + ftdi->usb_dev = NULL;
> + }
> + return ret;
> +}
Maybe we should prefix the function name with "ftdi_" to indicate
this belongs to libftdi. Something like ftdi_usb_close() ;-)
What about adding the "if (ftdi->usb_dev != NULL)"
check to the already existing ftdi_usb_close()?
git is a bit unhappy about the patch as your mail seems
to have wrapped long lines:
[tomj@storm src]$ git am /tmp/double_close.patch
Applying: Fix for double-free and segfault after close
fatal: corrupt patch at line 29
Cheers,
Thomas
--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|