diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-04-28 15:27:28 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-04-28 15:27:28 -0400 |
commit | 84ecd9606824b8e5bf01e5f80d47782c81489ad7 (patch) | |
tree | afaad2e0c224a8eeb368f1c205db55ee5a123da5 /netlib.c | |
parent | 664bdf0180091da0c720712b4c6d00f0bc066b02 (diff) | |
download | gpsd-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.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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; |