summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/hci.c13
-rw-r--r--src/sdp.c3
2 files changed, 11 insertions, 5 deletions
diff --git a/src/hci.c b/src/hci.c
index a9c482a2..05974432 100644
--- a/src/hci.c
+++ b/src/hci.c
@@ -647,21 +647,25 @@ int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg), long a
struct hci_dev_list_req *dl;
struct hci_dev_req *dr;
int dev_id = -1;
- int i, sk, err;
+ int i, sk, err = 0;
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0)
return -1;
dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
- if (!dl)
+ if (!dl) {
+ err = errno;
goto done;
+ }
dl->dev_num = HCI_MAX_DEV;
dr = dl->dev_req;
- if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0)
+ if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
+ err = errno;
goto free;
+ }
for (i = 0; i < dl->dev_num; i++, dr++) {
if (hci_test_bit(flag, &dr->dev_opt))
@@ -672,13 +676,12 @@ int hci_for_each_dev(int flag, int (*func)(int dd, int dev_id, long arg), long a
}
if (dev_id < 0)
- errno = ENODEV;
+ err = ENODEV;
free:
free(dl);
done:
- err = errno;
close(sk);
errno = err;
diff --git a/src/sdp.c b/src/sdp.c
index 0198f9ec..56c74d49 100644
--- a/src/sdp.c
+++ b/src/sdp.c
@@ -3160,6 +3160,7 @@ static inline int sdp_is_local(const bdaddr_t *device)
sdp_session_t *sdp_connect(const bdaddr_t *src, const bdaddr_t *dst, uint32_t flags)
{
+ int err;
sdp_session_t *session = malloc(sizeof(sdp_session_t));
if (!session)
return session;
@@ -3204,8 +3205,10 @@ sdp_session_t *sdp_connect(const bdaddr_t *src, const bdaddr_t *dst, uint32_t fl
}
}
fail:
+ err = errno;
if (session->sock >= 0)
close(session->sock);
free(session);
+ errno = err;
return 0;
}