All: Replace malloc+memset with calloc
authorDavidlohr Bueso <dave@gnu.org>
Wed, 11 Jul 2012 12:53:00 +0000 (13:53 +0100)
committerPete Batard <pete@akeo.ie>
Fri, 13 Jul 2012 14:59:57 +0000 (15:59 +0100)
libusb/core.c
libusb/io.c
libusb/os/linux_usbfs.c
libusb/version_nano.h

index e10d808..eccc216 100644 (file)
@@ -1628,12 +1628,11 @@ int API_EXPORTED libusb_init(libusb_context **context)
                return 0;
        }
 
-       ctx = malloc(sizeof(*ctx));
+       ctx = calloc(1, sizeof(*ctx));
        if (!ctx) {
                r = LIBUSB_ERROR_NO_MEM;
                goto err_unlock;
        }
-       memset(ctx, 0, sizeof(*ctx));
 
 #ifdef ENABLE_DEBUG_LOGGING
        ctx->debug = LIBUSB_LOG_LEVEL_DEBUG;
index d06d375..b8d445c 100644 (file)
@@ -1232,11 +1232,10 @@ struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
                + sizeof(struct libusb_transfer)
                + (sizeof(struct libusb_iso_packet_descriptor) * iso_packets)
                + os_alloc_size;
-       struct usbi_transfer *itransfer = malloc(alloc_size);
+       struct usbi_transfer *itransfer = calloc(1, alloc_size);
        if (!itransfer)
                return NULL;
 
-       memset(itransfer, 0, alloc_size);
        itransfer->num_iso_packets = iso_packets;
        usbi_mutex_init(&itransfer->lock, NULL);
        return USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
index a01fff8..dad7536 100644 (file)
@@ -1679,10 +1679,9 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer,
        usbi_dbg("need %d urbs for new transfer with length %d", num_urbs,
                transfer->length);
        alloc_size = num_urbs * sizeof(struct usbfs_urb);
-       urbs = malloc(alloc_size);
+       urbs = calloc(1, alloc_size);
        if (!urbs)
                return LIBUSB_ERROR_NO_MEM;
-       memset(urbs, 0, alloc_size);
        tpriv->urbs = urbs;
        tpriv->num_urbs = num_urbs;
        tpriv->num_retired = 0;
@@ -1808,10 +1807,9 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
        usbi_dbg("need %d 32k URBs for transfer", num_urbs);
 
        alloc_size = num_urbs * sizeof(*urbs);
-       urbs = malloc(alloc_size);
+       urbs = calloc(1, alloc_size);
        if (!urbs)
                return LIBUSB_ERROR_NO_MEM;
-       memset(urbs, 0, alloc_size);
 
        tpriv->iso_urbs = urbs;
        tpriv->num_urbs = num_urbs;
@@ -1845,12 +1843,11 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
 
                alloc_size = sizeof(*urb)
                        + (urb_packet_offset * sizeof(struct usbfs_iso_packet_desc));
-               urb = malloc(alloc_size);
+               urb = calloc(1, alloc_size);
                if (!urb) {
                        free_iso_urbs(tpriv);
                        return LIBUSB_ERROR_NO_MEM;
                }
-               memset(urb, 0, alloc_size);
                urbs[i] = urb;
 
                /* populate packet lengths */
@@ -1934,10 +1931,9 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
        if (transfer->length - LIBUSB_CONTROL_SETUP_SIZE > MAX_CTRL_BUFFER_LENGTH)
                return LIBUSB_ERROR_INVALID_PARAM;
 
-       urb = malloc(sizeof(struct usbfs_urb));
+       urb = calloc(1, sizeof(struct usbfs_urb));
        if (!urb)
                return LIBUSB_ERROR_NO_MEM;
-       memset(urb, 0, sizeof(struct usbfs_urb));
        tpriv->urbs = urb;
        tpriv->num_urbs = 1;
        tpriv->reap_action = NORMAL;
index 6fc6748..e6ad1ad 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10537
+#define LIBUSB_NANO 10538