You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/02/06 03:56:41 UTC
svn commit: r151534 -
incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Author: trustin
Date: Sat Feb 5 18:56:40 2005
New Revision: 151534
URL: http://svn.apache.org/viewcvs?view=rev&rev=151534
Log:
Added some detection code to notify users if they released the allocated buffers more than once.
Modified:
incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java?view=diff&r1=151533&r2=151534
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java Sat Feb 5 18:56:40 2005
@@ -91,6 +91,17 @@
}
buf.clear();
+ // Check leaked or dangling ByteBuffer.
+ if (buf.inUse)
+ {
+ throw new IllegalStateException(
+ "Already allocated buffer. Did you release the buffer more than once?");
+ }
+ else
+ {
+ buf.inUse = true;
+ }
+
return buf;
}
@@ -102,6 +113,17 @@
Stack stack = bufferStacks[ getBufferStackIndex( buf.capacity() ) ];
synchronized( stack )
{
+ // Check leaked or dangling ByteBuffer.
+ if (!buf.inUse)
+ {
+ throw new IllegalStateException(
+ "Already released buffer. Did you release the buffer more than once?");
+ }
+ else
+ {
+ buf.inUse = false; // clear the flag
+ }
+
stack.push( buf );
}
}
@@ -138,6 +160,7 @@
}
private final java.nio.ByteBuffer buf;
+ private boolean inUse;
private ByteBuffer( java.nio.ByteBuffer buf )
{