summaryrefslogtreecommitdiffstats
path: root/libc
diff options
context:
space:
mode:
authorErik Kline <ek@google.com>2016-03-04 17:16:55 +0900
committerAlexander Martinz <eviscerationls@gmail.com>2016-03-09 09:07:04 -0800
commite31f2d8c7de0d3f38329695afc12a7a74711dd26 (patch)
tree3a03bc3016fe07f70580a45ed603b5bccfa098a7 /libc
parent1bb333cd6711ebe80a1bc3a63298eb882297dcca (diff)
downloadbionic-e31f2d8c7de0d3f38329695afc12a7a74711dd26.zip
bionic-e31f2d8c7de0d3f38329695afc12a7a74711dd26.tar.gz
bionic-e31f2d8c7de0d3f38329695afc12a7a74711dd26.tar.bz2
Don't leak sockets if setsockopt() or fchown() fail.
Change-Id: Idcf8c08ff50d21c3a04b7ef80c4044f3f9762f2b
Diffstat (limited to 'libc')
-rw-r--r--libc/dns/net/getaddrinfo.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 829b679..cc8b8b4 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -1791,10 +1791,14 @@ _find_src_addr(const struct sockaddr *addr, struct sockaddr *src_addr, unsigned
return -1;
}
}
- if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0)
+ if (mark != MARK_UNSET && setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
+ close(sock);
return 0;
- if (uid > 0 && uid != NET_CONTEXT_INVALID_UID && fchown(sock, uid, (gid_t)-1) < 0)
+ }
+ if (uid > 0 && uid != NET_CONTEXT_INVALID_UID && fchown(sock, uid, (gid_t)-1) < 0) {
+ close(sock);
return 0;
+ }
do {
ret = __connect(sock, addr, len);
} while (ret == -1 && errno == EINTR);