2014-01-03 12:54:44

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 1/3] btinfo: Add missing socket close() on exit

From: Andrei Emeltchenko <[email protected]>

---
tools/btinfo.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/btinfo.c b/tools/btinfo.c
index 0f0dfad..aa4df5a 100644
--- a/tools/btinfo.c
+++ b/tools/btinfo.c
@@ -359,6 +359,8 @@ int main(int argc, char *argv[])

if (ioctl(fd, HCIDEVDOWN, hci_info.dev_id) < 0)
perror("Failed to power down controller");
+
+ close(fd);
}
}

--
1.8.3.2



2014-01-03 18:30:35

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 2/3] btmon: Fix memory leak

Hi Andrei,

> Dynamic memory stored in company allocated through function
> hwdb_get_company shall be freed.
> ---
> monitor/packet.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/monitor/packet.c b/monitor/packet.c
> index c991d04..b271cae 100644
> --- a/monitor/packet.c
> +++ b/monitor/packet.c
> @@ -408,18 +408,20 @@ static void print_addr(const char *label, const uint8_t *addr,
> if (!hwdb_get_company(addr, &company))
> company = NULL;
>
> - if (company)
> + if (company) {
> print_field("%s: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
> " (%s)", label, addr[5], addr[4],
> addr[3], addr[2],
> addr[1], addr[0],
> company);
> - else
> + free(company);

good catch. I totally forgot about the fact that the memory is allocated.

> + } else {
> print_field("%s: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
> " (OUI %2.2X-%2.2X-%2.2X)", label,
> addr[5], addr[4], addr[3],
> addr[2], addr[1], addr[0],
> addr[5], addr[4], addr[3]);
> + }
> break;

In userspace we do not require the else statement to be enclose by { } if the if part is as well. We usually don?t.

Regards

Marcel


2014-01-03 13:53:24

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/3] btinfo: Add missing socket close() on exit

Hi Andrei,

On Fri, Jan 03, 2014, Andrei Emeltchenko wrote:
> ---
> tools/btinfo.c | 2 ++
> 1 file changed, 2 insertions(+)

All three patches have been applied. Thanks.

Johan

2014-01-03 12:54:46

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 3/3] btproxy: Fix closing invalid file descriptor

From: Andrei Emeltchenko <[email protected]>

Instead of invalid file descriptor dst_fd close src_fd.
---
tools/btproxy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/btproxy.c b/tools/btproxy.c
index 3c7c48f..1573587 100644
--- a/tools/btproxy.c
+++ b/tools/btproxy.c
@@ -659,7 +659,7 @@ int main(int argc, char *argv[])

dst_fd = open_vhci(0x00);
if (dst_fd < 0) {
- close(dst_fd);
+ close(src_fd);
return EXIT_FAILURE;
}

--
1.8.3.2


2014-01-03 12:54:45

by Andrei Emeltchenko

[permalink] [raw]
Subject: [PATCH 2/3] btmon: Fix memory leak

From: Andrei Emeltchenko <[email protected]>

Dynamic memory stored in company allocated through function
hwdb_get_company shall be freed.
---
monitor/packet.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index c991d04..b271cae 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -408,18 +408,20 @@ static void print_addr(const char *label, const uint8_t *addr,
if (!hwdb_get_company(addr, &company))
company = NULL;

- if (company)
+ if (company) {
print_field("%s: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
" (%s)", label, addr[5], addr[4],
addr[3], addr[2],
addr[1], addr[0],
company);
- else
+ free(company);
+ } else {
print_field("%s: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"
" (OUI %2.2X-%2.2X-%2.2X)", label,
addr[5], addr[4], addr[3],
addr[2], addr[1], addr[0],
addr[5], addr[4], addr[3]);
+ }
break;
case 0x01:
switch ((addr[5] & 0xc0) >> 6) {
--
1.8.3.2