“74bc2ecfb5ca14d22eec1b6b8d476735067fa8db”上不存在“test/java/util/TimeZone/HongKong.java”
提交 95675113 编写于 作者: J jzavgren

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
上级 61677c05
...@@ -256,14 +256,14 @@ JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketRece ...@@ -256,14 +256,14 @@ JNIEXPORT jint JNICALL Java_java_net_DualStackPlainDatagramSocketImpl_socketRece
packetBuffer = (*env)->GetObjectField(env, dpObj, dp_bufID); packetBuffer = (*env)->GetObjectField(env, dpObj, dp_bufID);
packetBufferOffset = (*env)->GetIntField(env, dpObj, dp_offsetID); packetBufferOffset = (*env)->GetIntField(env, dpObj, dp_offsetID);
packetBufferLen = (*env)->GetIntField(env, dpObj, dp_bufLengthID); packetBufferLen = (*env)->GetIntField(env, dpObj, dp_bufLengthID);
if (packetBufferLen > MAX_BUFFER_LEN) {
/* Note: the buffer needn't be greater than 65,536 (0xFFFF) /* Note: the buffer needn't be greater than 65,536 (0xFFFF)
* the max size of an IP packet. Anything bigger is truncated anyway. * the max size of an IP packet. Anything bigger is truncated anyway.
*/ */
if (packetBufferLen > MAX_PACKET_LEN) { if (packetBufferLen > MAX_PACKET_LEN) {
packetBufferLen = MAX_PACKET_LEN; packetBufferLen = MAX_PACKET_LEN;
} }
if (packetBufferLen > MAX_BUFFER_LEN) {
fullPacket = (char *)malloc(packetBufferLen); fullPacket = (char *)malloc(packetBufferLen);
if (!fullPacket) { if (!fullPacket) {
JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed"); JNU_ThrowOutOfMemoryError(env, "Native heap allocation failed");
......
...@@ -145,7 +145,7 @@ static int getFD1(JNIEnv *env, jobject this) { ...@@ -145,7 +145,7 @@ static int getFD1(JNIEnv *env, jobject this) {
/* /*
* This function returns JNI_TRUE if the datagram size exceeds the underlying * This function returns JNI_TRUE if the datagram size exceeds the underlying
* provider's ability to send to the target address. The following OS * 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 * 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. * on the same machine then the send will fail silently.
...@@ -218,7 +218,7 @@ jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size) ...@@ -218,7 +218,7 @@ jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size)
/* /*
* Step 3: On Windows 95/98 then enumerate the IP addresses on * 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. * datagram is being sent to an application on the same machine.
*/ */
if (is95or98) { if (is95or98) {
...@@ -565,8 +565,8 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi ...@@ -565,8 +565,8 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0(JNIEnv *env, jobject thi
if (xp_or_later) { if (xp_or_later) {
/* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which /* SIO_UDP_CONNRESET fixes a bug introduced in Windows 2000, which
* returns connection reset errors un connected UDP sockets (as well * returns connection reset errors on connected UDP sockets (as well
* as connected sockets. The solution is to only enable this feature * as connected sockets). The solution is to only enable this feature
* when the socket is connected * when the socket is connected
*/ */
DWORD x1, x2; /* ignored result codes */ DWORD x1, x2; /* ignored result codes */
...@@ -690,6 +690,12 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -690,6 +690,12 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID); fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
packetBufferLen = (*env)->GetIntField(env, packet, dp_lengthID); 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) { if (connected) {
addrp = 0; /* arg to JVM_Sendto () null in this case */ addrp = 0; /* arg to JVM_Sendto () null in this case */
...@@ -728,7 +734,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this, ...@@ -728,7 +734,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send(JNIEnv *env, jobject this,
} }
/* When JNI-ifying the JDK's IO routines, we turned /* 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. * than 2048 bytes into several operations of size 2048.
* This saves a malloc()/memcpy()/free() for big * This saves a malloc()/memcpy()/free() for big
* buffers. This is OK for file IO and TCP, but that * buffers. This is OK for file IO and TCP, but that
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册