From owner-p4-projects@FreeBSD.ORG Sun Jul 5 19:47:14 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A44C91065673; Sun, 5 Jul 2009 19:47:13 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6176E1065672 for ; Sun, 5 Jul 2009 19:47:13 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 34BA58FC17 for ; Sun, 5 Jul 2009 19:47:13 +0000 (UTC) (envelope-from syl@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n65JlCV8012572 for ; Sun, 5 Jul 2009 19:47:12 GMT (envelope-from syl@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n65JlC9E012570 for perforce@freebsd.org; Sun, 5 Jul 2009 19:47:12 GMT (envelope-from syl@FreeBSD.org) Date: Sun, 5 Jul 2009 19:47:12 GMT Message-Id: <200907051947.n65JlC9E012570@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to syl@FreeBSD.org using -f From: Sylvestre Gallon To: Perforce Change Reviews Cc: Subject: PERFORCE change 165653 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 05 Jul 2009 19:47:14 -0000 http://perforce.freebsd.org/chv.cgi?CH=165653 Change 165653 by syl@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; }