Try to clear up some valgrind complaints

This commit is contained in:
Neale Pickett 2013-09-08 20:32:42 -06:00
parent 22f6bc30de
commit 3faaf4ab07
1 changed files with 19 additions and 14 deletions

33
usb.c
View File

@ -9,9 +9,7 @@
#include "dump.h" #include "dump.h"
static struct libusb_device_handle *usb_dev; static struct libusb_device_handle *usb_dev;
static struct libusb_transfer *xfer = NULL;
static const struct device *d; static const struct device *d;
uint8_t data[80];
struct device { struct device {
uint16_t product_id; uint16_t product_id;
@ -30,23 +28,26 @@ void usb_xfer_done(struct libusb_transfer *transfer);
static void static void
usb_initiate_transfer() usb_initiate_transfer()
{ {
unsigned char *buf;
buf = (unsigned char *)malloc(256);
// Tell libusb we want to know about bulk transfers // Tell libusb we want to know about bulk transfers
if (xfer) { struct libusb_transfer *xfer = libusb_alloc_transfer(0);
libusb_free_transfer(xfer); libusb_fill_bulk_transfer(xfer, usb_dev, d->ep_in, buf, 256, usb_xfer_done, NULL, 0);
}
xfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(xfer, usb_dev, d->ep_in, data, sizeof(data), usb_xfer_done, NULL, 0);
libusb_submit_transfer(xfer); libusb_submit_transfer(xfer);
} }
void void
usb_xfer_done(struct libusb_transfer *transfer) usb_xfer_done(struct libusb_transfer *xfer)
{ {
uint8_t *data = transfer->buffer; uint8_t *data = xfer->buffer;
int datalen = transfer->actual_length; int datalen = xfer->actual_length;
alsa_write(data, datalen); alsa_write(data, datalen);
usb_initiate_transfer(); free(data);
libusb_free_transfer(xfer);
usb_initiate_transfer();
} }
int int
@ -137,17 +138,21 @@ usb_check_fds(fd_set *rfds, fd_set *wfds)
void void
usb_write_done(struct libusb_transfer *transfer) usb_write_done(struct libusb_transfer *xfer)
{ {
libusb_free_transfer(transfer); free(xfer->buffer);
libusb_free_transfer(xfer);
} }
void void
usb_write(uint8_t *data, size_t datalen) usb_write(uint8_t *data, size_t datalen)
{ {
struct libusb_transfer *xfer; struct libusb_transfer *xfer;
unsigned char *buf;
xfer = libusb_alloc_transfer(0); xfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(xfer, usb_dev, d->ep_out, data, datalen, usb_write_done, NULL, 0); buf = (unsigned char *)malloc(datalen);
memcpy(buf, data, datalen);
libusb_fill_bulk_transfer(xfer, usb_dev, d->ep_out, buf, datalen, usb_write_done, NULL, 0);
libusb_submit_transfer(xfer); libusb_submit_transfer(xfer);
} }