You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/06/17 10:22:18 UTC

svn commit: r785506 - in /commons/sandbox/runtime/trunk/src: main/native/shared/dbb.c test/org/apache/commons/runtime/TestDirectByteBuffer.java test/org/apache/commons/runtime/TestPrivate.java

Author: mturk
Date: Wed Jun 17 08:22:17 2009
New Revision: 785506

URL: http://svn.apache.org/viewvc?rev=785506&view=rev
Log:
Test for double free(). Still doesn't work on all platforms as expected

Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c?rev=785506&r1=785505&r2=785506&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dbb.c Wed Jun 17 08:22:17 2009
@@ -21,11 +21,12 @@
 
 #include "acr.h"
 #include "acr_private.h"
-#define  ACR_WANT_MEMPROTECT
-#include "acr_error.h"
 #include "acr_clazz.h"
 #include "acr_pointer.h"
 
+#define  ACR_WANT_MEMPROTECT
+#include "acr_error.h"
+
 /**
  * DirectByteBuffer utilities
  */
@@ -415,6 +416,9 @@
         ACR_TRY {
             free(mem);
         } ACR_CATCH() {
+            /* XXX: Unstable. 
+             * On linux this works only if MALLOC_CHECK_=1 envvar is set
+             */
             ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ERUNTIME, EFAULT);
         }
     }

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java?rev=785506&r1=785505&r2=785506&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestDirectByteBuffer.java Wed Jun 17 08:22:17 2009
@@ -77,6 +77,28 @@
          */
     }
 
+    public void testPointerDontDoThis()
+        throws Exception
+    {
+        // ptr, bb1 and bb2 share the same memory
+        Pointer ptr = Memory.malloc(1000);
+        ByteBuffer bb = DirectByteBuffer.allocate(ptr);
+        assertTrue("Direct", bb.isDirect());
+        assertEquals("Capacity", 1000, bb.capacity());
+        try {
+                Native.enableExceptionHandler();
+              ptr.free();
+            // This is double free. Don't do this!
+            if (OS.TYPE.contains(OsType.WINDOWS)) {
+                // TODO: Check for MALLOC_CHECK_ envvar.
+                DirectByteBuffer.free(bb);
+            }
+        } catch (Throwable t) {
+            assertSame("Wrong Exception class",
+                java.lang.RuntimeException.class, t.getClass());
+        }
+    }
+
     public void testMemset()
         throws Exception
     {

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java?rev=785506&r1=785505&r2=785506&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestPrivate.java Wed Jun 17 08:22:17 2009
@@ -587,9 +587,9 @@
     public void testMempotect()
         throws Throwable
     {
-		Native.enableExceptionHandler();
-		try {
-        	test030(0);
+        Native.enableExceptionHandler();
+        try {
+            test030(0);
             fail("Exception not thrown");
         } catch (Throwable t) {
             assertSame("Wrong Exception class",