diff --git a/tools/hcidump.c b/tools/hcidump.c
index 8839eb0..af8f592 100644
--- a/tools/hcidump.c
+++ b/tools/hcidump.c
struct frame frm;
struct pollfd fds[2];
int nfds = 0;
- char *buf, *ctrl;
+ char *buf;
+ char ctrl[100];
int len, hdr_size = HCIDUMP_HDR_SIZE;
if (sock < 0)
dp = (void *) buf;
frm.data = buf + hdr_size;
- ctrl = malloc(100);
- if (!ctrl) {
- free(buf);
- perror("Can't allocate control buffer");
- return -1;
- }
-
if (dev == HCI_DEV_NONE)
printf("system: ");
else
opt = 1;
if (setsockopt(sk, SOL_HCI, HCI_DATA_DIR, &opt, sizeof(opt)) < 0) {
perror("Can't enable data direction info");
- return -1;
+ goto fail;
}
opt = 1;
if (setsockopt(sk, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
perror("Can't enable time stamp");
- return -1;
+ goto fail;
}
/* Setup filter */
hci_filter_all_events(&flt);
if (setsockopt(sk, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
perror("Can't set filter");
- return -1;
+ goto fail;
}
/* Bind socket to the HCI device */
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
printf("Can't attach to device hci%d. %s(%d)\n",
dev, strerror(errno), errno);
- return -1;
+ goto fail;
}
return sk;
+
+fail:
+ close(sk);
+ return -1;
}
static struct {