Mercurial > hg > jdk9-shenandoah > jdk
changeset 12748:bb6e5a409fef
8073542: File Leak in jdk/src/java/base/unix/native/libnet/PlainDatagramSocketImpl.c
Summary: ensure that file descriptor is properly closed if setsockopt fails.
Reviewed-by: chegar, igerasim
Contributed-by: vyom.tewari@oracle.com
author | dfuchs |
---|---|
date | Thu, 17 Sep 2015 17:33:00 +0200 |
parents | 4be07e0eb9b6 |
children | acf424f856ce |
files | src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c |
diffstat | 1 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Thu Sep 17 10:37:39 2015 +0800 +++ b/src/java.base/unix/native/libnet/PlainDatagramSocketImpl.c Thu Sep 17 17:33:00 2015 +0200 @@ -955,17 +955,23 @@ (char *)&arg, sizeof(arg)) < 0) { JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", strerror(errno)); + close(fd); return; } if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&arg, sizeof(arg)) < 0) { JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", strerror(errno)); + close(fd); return; } #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__) arg = 0; @@ -986,8 +992,12 @@ */ if (domain == AF_INET6) { int ttl = 1; - setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&ttl, - sizeof(ttl)); + if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *) &ttl, + sizeof (ttl)) < 0) { + JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", strerror(errno)); + close(fd); + return; + } } #endif /* __linux__ */