summaryrefslogtreecommitdiff
path: root/netlib.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2010-04-28 15:27:28 -0400
committerEric S. Raymond <esr@thyrsus.com>2010-04-28 15:27:28 -0400
commit84ecd9606824b8e5bf01e5f80d47782c81489ad7 (patch)
treeafaad2e0c224a8eeb368f1c205db55ee5a123da5 /netlib.c
parent664bdf0180091da0c720712b4c6d00f0bc066b02 (diff)
downloadgpsd-84ecd9606824b8e5bf01e5f80d47782c81489ad7.tar.gz
Prevent an unlikely (but possible) fd leak. All regression tests pass, code splints clean.
Diffstat (limited to 'netlib.c')
-rw-r--r--netlib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/netlib.c b/netlib.c
index a385ba95..9726f36f 100644
--- a/netlib.c
+++ b/netlib.c
@@ -70,10 +70,10 @@ socket_t netlib_connectsock(int af, const char *host, const char *service,
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = af;
hints.ai_socktype = type;
- if (bind_me)
- hints.ai_flags = AI_PASSIVE;
hints.ai_protocol = proto;
#ifndef S_SPLINT_S
+ if (bind_me)
+ hints.ai_flags = AI_PASSIVE;
if ((ret = getaddrinfo(host, service, &hints, &result))) {
return NL_NOHOST;
}
@@ -96,9 +96,10 @@ socket_t netlib_connectsock(int af, const char *host, const char *service,
ret = NL_NOSOCK;
else if (setsockopt
(s, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
- sizeof(one)) == -1)
+ sizeof(one)) == -1) {
+ (void)close(s);
ret = NL_NOSOCKOPT;
- else {
+ } else {
if (bind_me) {
if (bind(s, rp->ai_addr, rp->ai_addrlen) == 0) {
ret = 0;