PERFORCE change 165653 for review
Sylvestre Gallon
syl at FreeBSD.org
Sun Jul 5 19:47:14 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=165653
Change 165653 by syl at syl_atuin on 2009/07/05 19:46:41
Replace a malloc by alloca.
Remove a possible uninitialized return value in libusb_get_buffsize.
Remove 2 possible NULL dereference.
Affected files ...
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#57 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#19 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#23 edit
Differences ...
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#57 (text+ko) ====
@@ -889,11 +889,10 @@
case LIBUSB20_SPEED_FULL:
ret = 64;
break ;
- case LIBUSB20_SPEED_HIGH:
+ default:
ret = 64;
break ;
}
- /*add */
ret += 8;
break ;
default :
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#19 (text+ko) ====
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_io.c#23 (text+ko) ====
@@ -254,7 +254,7 @@
TAILQ_FOREACH(ipollfd, &ctx->pollfds, list)
nfds++;
- fds = malloc(sizeof(*fds) * nfds);
+ fds = alloca(sizeof(*fds) * nfds);
if (fds == NULL)
return (LIBUSB_ERROR_NO_MEM);
@@ -274,16 +274,12 @@
timeout++;
ret = poll(fds, nfds, timeout);
- if (ret == 0) {
- free(fds);
+ if (ret == 0)
return (handle_timeouts(ctx));
- } else if (ret == -1 && errno == EINTR) {
- free(fds);
+ else if (ret == -1 && errno == EINTR)
return (LIBUSB_ERROR_INTERRUPTED);
- } else if (ret < 0) {
- free(fds);
+ else if (ret < 0)
return (LIBUSB_ERROR_IO);
- }
if (fds[0].revents) {
if (ret == 1){
@@ -296,7 +292,7 @@
}
pthread_mutex_lock(&ctx->open_devs_lock);
- for (i = 0 ; i < nfds && ret > 0 ; i++) {
+ for (i = 0, devh = NULL ; i < nfds && ret > 0 ; i++) {
tfds = &fds[i];
if (!tfds->revents)
@@ -310,14 +306,16 @@
if (tfds->revents & POLLERR) {
usb_remove_pollfd(ctx, libusb20_dev_get_fd(devh->os_priv));
- usb_handle_disconnect(devh);
+ if (devh != NULL)
+ usb_handle_disconnect(devh);
continue ;
}
pthread_mutex_lock(&libusb20_lock);
DPRINTF(ctx, LIBUSB_DEBUG_TRANSFER, "LIBUSB20_PROCESS");
- ret = libusb20_dev_process(devh->os_priv);
+ if (devh != NULL)
+ ret = libusb20_dev_process(devh->os_priv);
pthread_mutex_unlock(&libusb20_lock);
@@ -332,7 +330,6 @@
pthread_mutex_unlock(&ctx->open_devs_lock);
handled:
- free(fds);
DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "handle_events leave");
return ret;
}
More information about the p4-projects
mailing list