8073542: File Leak in jdk/src/java/base/unix/native/libnet/PlainDatagramSocketImpl.c
Ensure that file descriptor is properly closed if setsockopt fails. Reviewed-by: chegar, igerasim
This commit is contained in:
parent
d9f30b845c
commit
681e6b478b
@ -955,17 +955,23 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
|
|||||||
(char *)&arg, sizeof(arg)) < 0) {
|
(char *)&arg, sizeof(arg)) < 0) {
|
||||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
|
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
|
||||||
(char *)&arg, sizeof(arg)) < 0) {
|
(char *)&arg, sizeof(arg)) < 0) {
|
||||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
close(fd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* __APPLE__ */
|
#endif /* __APPLE__ */
|
||||||
|
|
||||||
setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof(int));
|
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof (int)) < 0) {
|
||||||
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
arg = 0;
|
arg = 0;
|
||||||
@ -986,8 +992,12 @@ Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
|
|||||||
*/
|
*/
|
||||||
if (domain == AF_INET6) {
|
if (domain == AF_INET6) {
|
||||||
int ttl = 1;
|
int ttl = 1;
|
||||||
setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&ttl,
|
if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *) &ttl,
|
||||||
sizeof(ttl));
|
sizeof (ttl)) < 0) {
|
||||||
|
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* __linux__ */
|
#endif /* __linux__ */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user