harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hinde...@apache.org
Subject svn commit: r584758 - /harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
Date Mon, 15 Oct 2007 12:03:23 GMT
Author: hindessm
Date: Mon Oct 15 05:03:22 2007
New Revision: 584758

URL: http://svn.apache.org/viewvc?rev=584758&view=rev
Log:
Make sure there are references to the ByteBuffers for as long as there
are references to the addresses in those buffers.  Otherwise, "handles[]"
can be used after the RuntimeMemorySpy has free'd the memory that they
reference.

This fixes intermittent failures of the FileChannelTest
test_write$LByteBufferII(), where the first buffer was corrupted because
it has been free'd by the RuntimeMemorySpy during the alloc of the second.

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java?rev=584758&r1=584757&r2=584758&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/FileChannelImpl.java
Mon Oct 15 05:03:22 2007
@@ -582,6 +582,7 @@
         long[] handles = new long[length];
         int[] offsets = new int[length];
         int[] lengths = new int[length];
+        ByteBuffer[] bufferRefs = new ByteBuffer[length];
         for (int i = 0; i < length; i++) {
             ByteBuffer buffer = buffers[i + offset];
             if (!buffer.isDirect()) {
@@ -596,6 +597,7 @@
             }
             handles[i] = ((DirectBuffer) buffer).getEffectiveAddress().toLong();
             lengths[i] = buffer.remaining();
+            bufferRefs[i] = buffer;
         }
 
         long bytesWritten = 0;



Mime
View raw message