directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r151534 - incubator/directory/network/trunk/mina/src/java/org/apache/mina/common/ByteBuffer.java
Date Sun, 06 Feb 2005 02:56:41 GMT
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 )
     {



Mime
View raw message