diff options
author | Gaurav <g.gupta@samsung.com> | 2015-06-19 08:53:59 +0530 |
---|---|---|
committer | Nathan Hjelm <hjelmn@me.com> | 2016-03-06 14:40:30 -0700 |
commit | 98dd33c41ab12db437112b662821e7f133a4eac9 (patch) | |
tree | 230db5537461eb30a3c13d3ba54ba77b27d9c8cb /libusb/descriptor.c | |
parent | 40fb6ff0a0cb67343b722a6b6227f21142cb18cd (diff) | |
download | libusb-98dd33c41ab12db437112b662821e7f133a4eac9.tar.gz |
free can handle NULL ptr.
free(NULL) is no operation.
Contributed by @ya1gaurav.
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
Diffstat (limited to 'libusb/descriptor.c')
-rw-r--r-- | libusb/descriptor.c | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/libusb/descriptor.c b/libusb/descriptor.c index ccf7fe4..d784be8 100644 --- a/libusb/descriptor.c +++ b/libusb/descriptor.c @@ -94,8 +94,7 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor, static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint) { - if (endpoint->extra) - free((unsigned char *) endpoint->extra); + free(endpoint->extra); } static int parse_endpoint(struct libusb_context *ctx, @@ -193,24 +192,18 @@ static void clear_interface(struct libusb_interface *usb_interface) int i; int j; - if (usb_interface->altsetting) { - for (i = 0; i < usb_interface->num_altsetting; i++) { - struct libusb_interface_descriptor *ifp = - (struct libusb_interface_descriptor *) - usb_interface->altsetting + i; - if (ifp->extra) - free((void *) ifp->extra); - if (ifp->endpoint) { - for (j = 0; j < ifp->bNumEndpoints; j++) - clear_endpoint((struct libusb_endpoint_descriptor *) - ifp->endpoint + j); - free((void *) ifp->endpoint); - } - } - free((void *) usb_interface->altsetting); - usb_interface->altsetting = NULL; + for (i = 0; i < usb_interface->num_altsetting; i++) { + struct libusb_interface_descriptor *ifp = + (struct libusb_interface_descriptor *) + usb_interface->altsetting + i; + free(ifp->extra); + for (j = 0; j < ifp->bNumEndpoints; j++) + clear_endpoint((struct libusb_endpoint_descriptor *) + ifp->endpoint + j); + free(ifp->endpoint); } - + free(usb_interface->altsetting); + usb_interface->altsetting = NULL; } static int parse_interface(libusb_context *ctx, @@ -361,15 +354,12 @@ err: static void clear_configuration(struct libusb_config_descriptor *config) { - if (config->interface) { - int i; - for (i = 0; i < config->bNumInterfaces; i++) - clear_interface((struct libusb_interface *) - config->interface + i); - free((void *) config->interface); - } - if (config->extra) - free((void *) config->extra); + int i; + for (i = 0; i < config->bNumInterfaces; i++) + clear_interface((struct libusb_interface *) + config->interface + i); + free(config->interface); + free(config->extra); } static int parse_configuration(struct libusb_context *ctx, |