The branch main has been updated by aokblast: URL: https://cgit.FreeBSD.org/src/commit/?id=1c675fb36545e9da8eef995140275263fd169d3b
commit 1c675fb36545e9da8eef995140275263fd169d3b Author: ShengYi Hung <aokbl...@freebsd.org> AuthorDate: 2025-07-09 07:38:17 +0000 Commit: ShengYi Hung <aokbl...@freebsd.org> CommitDate: 2025-07-21 06:15:15 +0000 libusb: implement libusb_free_pollfds libusb provides an API that frees the storage for pollfds regardless of their contents. It does not check whether the file descriptors inside are already closed. Approved by: markj (mentor), lwhsu(mentor) MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51221 --- lib/libusb/libusb.3 | 6 ++++++ lib/libusb/libusb.h | 3 ++- lib/libusb/libusb10_io.c | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3 index 74b85d4aa17e..da927f8985a8 100644 --- a/lib/libusb/libusb.3 +++ b/lib/libusb/libusb.3 @@ -775,6 +775,12 @@ argument can be either of LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED or LIBUSB_HOTPLUG_ .Ft void .Fn libusb_hotplug_deregister_callback "libusb_context *ctx" "libusb_hotplug_callback_handle handle" This function unregisters a hotplug filter. +.Pp +.Ft void +.Fn libusb_free_pollfds "const struct libusb_pollfd **pollfds" +This function releases the memory storage in +.Fa pollfds , +and is safe to call when the argument is NULL. .Sh LIBUSB VERSION 0.1 COMPATIBILITY The library is also compliant with LibUSB version 0.1.12. .Pp diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 6fb1c19fad13..1962152c0b68 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -573,7 +573,8 @@ int libusb_handle_events(libusb_context * ctx); int libusb_handle_events_locked(libusb_context * ctx, struct timeval *tv); int libusb_get_next_timeout(libusb_context * ctx, struct timeval *tv); void libusb_set_pollfd_notifiers(libusb_context * ctx, libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb, void *user_data); -const struct libusb_pollfd **libusb_get_pollfds(libusb_context * ctx); +const struct libusb_pollfd **libusb_get_pollfds(libusb_context *ctx); +void libusb_free_pollfds(const struct libusb_pollfd **pollfds); /* Synchronous device I/O */ diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index dd541b09caa6..ea365162df5a 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -842,3 +842,12 @@ libusb_transfer_get_stream_id(struct libusb_transfer *transfer) /* get stream ID */ return (sxfer->stream_id); } + +void +libusb_free_pollfds(const struct libusb_pollfd **pollfds) +{ + if (pollfds == NULL) + return; + + free(pollfds); +}