summaryrefslogtreecommitdiff
path: root/netlib.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-02 10:31:18 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-02 10:31:18 -0500
commitb159829e12ce30c6343b43c2ea48c4985f4f3731 (patch)
treee675d67a28976e8d264b78318849fc58527ac43e /netlib.c
parent2e38c5204a2461e1c033426e3213d860f3487f94 (diff)
downloadgpsd-b159829e12ce30c6343b43c2ea48c4985f4f3731.tar.gz
Guard a potentially fatal call better. All regression tests pass.
Diffstat (limited to 'netlib.c')
-rw-r--r--netlib.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/netlib.c b/netlib.c
index 00e0c2d0..e26b3e03 100644
--- a/netlib.c
+++ b/netlib.c
@@ -76,7 +76,8 @@ socket_t netlib_connectsock(int af, const char *host, const char *service,
else if (setsockopt
(s, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
sizeof(one)) == -1) {
- (void)close(s);
+ if (s > -1)
+ (void)close(s);
ret = NL_NOSOCKOPT;
} else {
if (bind_me) {
@@ -92,7 +93,7 @@ socket_t netlib_connectsock(int af, const char *host, const char *service,
}
}
- if (s > 0) {
+ if (s > -1) {
(void)close(s);
}
}