about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2017-03-14 14:31:34 -0400
committerRich Felker <dalias@aerifal.cx>2017-03-14 14:31:34 -0400
commit6a209f14ff7273d9429e5153c5b6b1990cb508e3 (patch)
tree4d33c25887dbfce053dd3e552094b72b946fe1d5
parent500f5bee6c03981961f1586fca2a1dee6fdce7c7 (diff)
downloadmusl-6a209f14ff7273d9429e5153c5b6b1990cb508e3.tar.gz
musl-6a209f14ff7273d9429e5153c5b6b1990cb508e3.tar.xz
musl-6a209f14ff7273d9429e5153c5b6b1990cb508e3.zip
fix possible fd leak, unrestored cancellation state on dns socket fail
-rw-r--r--src/network/res_msend.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/network/res_msend.c b/src/network/res_msend.c
index de7f6157..3e018009 100644
--- a/src/network/res_msend.c
+++ b/src/network/res_msend.c
@@ -76,7 +76,11 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
 		fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
 		family = AF_INET;
 	}
-	if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) return -1;
+	if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
+		if (fd >= 0) close(fd);
+		pthread_setcancelstate(cs, 0);
+		return -1;
+	}
 
 	/* Past this point, there are no errors. Each individual query will
 	 * yield either no reply (indicated by zero length) or an answer