# HG changeset patch # User jzavgren # Date 1370028206 14400 # Node ID e8d88b57f82e9de0443d66a89deaefad4739a14d # Parent c4e51dc609b19097b7a757835e0868ea81de1cdd 8008972: Memory leak: Java_java_net_TwoStacksPlainDatagramSocketImpl_receive0 [parfait] Summary: Modified the code so that "jumbo frames" are truncated before buffer allocation is considered. This makes the buffer length a reliable indication that a buffer has been allocated, and it can then be used during clean up. Reviewed-by: chegar, khazra, alanb Contributed-by: john.zavgren@oracle.com diff -r c4e51dc609b1 -r e8d88b57f82e jdk/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c --- a/jdk/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c Fri May 31 13:34:27 2013 -0700 +++ b/jdk/src/windows/native/java/net/DualStackPlainDatagramSocketImpl.c Fri May 31 15:23:26 2013 -0400 @@ -256,14 +256,14 @@ packetBuffer = (*env)->GetObjectField(env, dpObj, dp_bufID); packetBufferOffset = (*env)->GetIntField(env, dpObj, dp_offsetID); packetBufferLen = (*env)->GetIntField(env, dpObj, dp_bufLengthID); + /* Note: the buffer needn't be greater than 65,536 (0xFFFF) + * the max size of an IP packet. Anything bigger is truncated anyway. + */ + if (packetBufferLen > MAX_PACKET_LEN) { + packetBufferLen = MAX_PACKET_LEN; + } if (packetBufferLen > MAX_BUFFER_LEN) { - /* Note: the buffer needn't be greater than 65,536 (0xFFFF) - * the max size of an IP packet. Anything bigger is truncated anyway. - */ - if (packetBufferLen > MAX_PACKET_LEN) { - packetBufferLen = MAX_PACKET_LEN; - } fullPacket = (char *)malloc(packetBufferLen); if (!fullPacket) { JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); diff -r c4e51dc609b1 -r e8d88b57f82e jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c --- a/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Fri May 31 13:34:27 2013 -0700 +++ b/jdk/src/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c Fri May 31 15:23:26 2013 -0400 @@ -145,7 +145,7 @@ /* * This function returns JNI_TRUE if the datagram size exceeds the underlying * provider's ability to send to the target address. The following OS - * oddies have been observed :- + * oddities have been observed :- * * 1. On Windows 95/98 if we try to send a datagram > 12k to an application * on the same machine then the send will fail silently. @@ -218,7 +218,7 @@ /* * Step 3: On Windows 95/98 then enumerate the IP addresses on - * this machine. This is necesary because we need to check if the + * this machine. This is neccesary because we need to check if the * datagram is being sent to an application on the same machine. */ if (is95or98) { @@ -565,8 +565,8 @@ if (xp_or_later) { /* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which - * returns connection reset errors un connected UDP sockets (as well - * as connected sockets. The solution is to only enable this feature + * returns connection reset errors on connected UDP sockets (as well + * as connected sockets). The solution is to only enable this feature * when the socket is connected */ DWORD x1, x2; /* ignored result codes */ @@ -690,6 +690,12 @@ fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); packetBufferLen = (*env)->GetIntField(env, packet, dp_lengthID); + /* Note: the buffer needn't be greater than 65,536 (0xFFFF)... + * the maximum size of an IP packet. Anything bigger is truncated anyway. + */ + if (packetBufferLen > MAX_PACKET_LEN) { + packetBufferLen = MAX_PACKET_LEN; + } if (connected) { addrp = 0; /* arg to JVM_Sendto () null in this case */ @@ -728,7 +734,7 @@ } /* When JNI-ifying the JDK's IO routines, we turned - * read's and write's of byte arrays of size greater + * reads and writes of byte arrays of size greater * than 2048 bytes into several operations of size 2048. * This saves a malloc()/memcpy()/free() for big * buffers. This is OK for file IO and TCP, but that