commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r890200 - in /commons/sandbox/runtime/trunk/src/main/native/os/win32: mmap.c shm.c
Date Mon, 14 Dec 2009 07:07:54 GMT
Author: mturk
Date: Mon Dec 14 07:07:54 2009
New Revision: 890200

URL: http://svn.apache.org/viewvc?rev=890200&view=rev
Log:
Do not close descriptors twice

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c?rev=890200&r1=890199&r2=890200&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/mmap.c Mon Dec 14 07:07:54 2009
@@ -56,7 +56,7 @@
 
 static int mmap_cleanup(void *map, int type, unsigned int flags)
 {
-    int rc = 0;
+    int rc = ACR_EBADF;
     acr_mmap_t *m = (acr_mmap_t *)map;
 
     if (type != ACR_DT_MMAP) {
@@ -65,14 +65,25 @@
     if (IS_VALID_MEMORY(m->base)) {
         if (!UnmapViewOfFile(m->base))
             rc = ACR_GET_OS_ERROR();
+        else
+            rc = ACR_SUCCESS;
+        m->base = NULL;
     }
-    if (!CloseHandle(m->mh))
-        rc = ACR_GET_OS_ERROR();
-    if ((flags & MMAP_OWNS_FILE)) {
+    if (IS_VALID_HANDLE(m->mh)) {
+        if (!CloseHandle(m->mh))
+            rc = rc ? rc : ACR_GET_OS_ERROR();
+        else
+            rc = rc ? rc : ACR_SUCCESS;
+        m->mh = INVALID_HANDLE_VALUE;
+    }
+    if ((flags & MMAP_OWNS_FILE) && IS_VALID_HANDLE(m->fd)) {
         /* Since we have opended the file close it.
          */
         if (!CloseHandle(m->fd))
-            rc = ACR_GET_OS_ERROR();
+            rc = rc ? rc : ACR_GET_OS_ERROR();
+        else
+            rc = rc ? rc : ACR_SUCCESS;
+        m->fd = INVALID_HANDLE_VALUE;
     }
     if (flags & ACR_IOH_CLEAR)
         x_free(m);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c?rev=890200&r1=890199&r2=890200&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c Mon Dec 14 07:07:54 2009
@@ -59,17 +59,25 @@
 
 static int shm_cleanup(void *shm, int type, unsigned int flags)
 {
-    int rc = 0;
+    int rc = ACR_EBADF;
     acr_shm_t *m = (acr_shm_t *)shm;
 
     if (type != ACR_DT_SHM) {
         return ACR_EFTYPE;
     }
-    if (m->memblk && !UnmapViewOfFile(m->memblk)) {
-        rc = ACR_GET_OS_ERROR();
-    }
-    if (!CloseHandle(m->hmap) && rc == 0) {
-        rc = ACR_GET_OS_ERROR();
+    if (IS_VALID_HANDLE(m->memblk)) {
+        if (!UnmapViewOfFile(m->memblk))
+            rc = ACR_GET_OS_ERROR();
+        else
+            rc = ACR_SUCCESS;
+        m->memblk = NULL;
+    }
+    if (IS_VALID_HANDLE(m->hmap)) {
+        if (!CloseHandle(m->hmap))
+            rc = rc ? rc : ACR_GET_OS_ERROR();
+        else
+            rc = rc ? rc : ACR_SUCCESS;
+        m->hmap = NULL;
     }
     if (m->filename) {
         /* Remove file if file backed.
@@ -80,14 +88,11 @@
         x_free((void *)(m->filename));
         m->filename = NULL;
     }
-    m->memblk = NULL;
-    m->hmap   = NULL;
     if (flags & ACR_IOH_CLEAR)
         x_free(m);
     return rc;
 }
 
-
 ACR_DECLARE(int) ACR_ShmClose(JNIEnv *_E, int shm)
 {
     int rc;



Mime
View raw message