commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r898807 - in /commons/sandbox/runtime/trunk/src/main/native: include/arch/windows/acr_arch_private.h os/win32/main.c os/win32/wusec.c
Date Wed, 13 Jan 2010 15:48:19 GMT
Author: mturk
Date: Wed Jan 13 15:48:18 2010
New Revision: 898807

URL: http://svn.apache.org/viewvc?rev=898807&view=rev
Log:
Add Heap and Local alloc macros

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=898807&r1=898806&r2=898807&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Wed Jan 13 15:48:18 2010
@@ -270,9 +270,12 @@
  */
 extern HANDLE dll_heap_handle;
 
-#define ACR_HeapMalloc(S)   HeapAlloc(dll_heap_handle, 0, (S))
-#define ACR_HeapCalloc(S)   HeapAlloc(dll_heap_handle, HEAP_ZERO_MEMORY, (S))
-#define ACR_HeapFree(M)     HeapFree(dll_heap_handle, 0, (M))
+#define ACR_HMALLOC(T, S)   (T *)(HeapAlloc(dll_heap_handle, 0, (S)))
+#define ACR_HCALLOC(T, S)   (T *)(HeapAlloc(dll_heap_handle, HEAP_ZERO_MEMORY, (S)))
+#define ACR_HFREE(M)        HeapFree(dll_heap_handle, 0, (M))
+
+#define ACR_LALLOC(T, S)    (T *)(LocalAlloc(LPTR, (S)))
+#define ACR_LFREE(M)        if ((M)) LocalFree((M))
 
 /**
  * Utility functions from wutil.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=898807&r1=898806&r2=898807&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Wed Jan 13 15:48:18 2010
@@ -73,9 +73,9 @@
         ACR_RING_REMOVE(c, link);
         if (c->size)
             x_free(c->data);
-        ACR_HeapFree(c);
+        ACR_HFREE(c);
     }
-    ACR_HeapFree(t);;
+    ACR_HFREE(t);
 }
 
 static void acr_dll_exit()
@@ -442,7 +442,7 @@
     if (tlsd == NULL) {
         if (GetLastError() != ERROR_SUCCESS)
             return &_null_tlsd;
-        tlsd = ACR_HeapCalloc(sizeof(acr_thread_local_t));
+        tlsd = ACR_HCALLOC(acr_thread_local_t, sizeof(acr_thread_local_t));
         if (tlsd == NULL) {
             memset(&_null_tlsd, 0, sizeof(acr_thread_local_t));
             return &_null_tlsd;
@@ -479,7 +479,7 @@
                 return ACR_EEXIST;
         }
     }
-    node = ACR_HeapCalloc(sizeof(acr_tlsd_data_t));
+    node = ACR_HCALLOC(acr_tlsd_data_t, sizeof(acr_tlsd_data_t));
     if (!node) {
         return ACR_ENOMEM;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c?rev=898807&r1=898806&r2=898807&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Wed Jan 13 15:48:18 2010
@@ -33,7 +33,7 @@
 #define SECURITY_UNL()                      \
     if (security_table)                     \
         LeaveCriticalSection(&security_lock)
-    
+
 PSID ACR_GetSidFromAccountName(LPCWSTR name, PSID_NAME_USE sidtype)
 {
     WCHAR domain[MAX_PATH];
@@ -106,7 +106,7 @@
 
     GetTokenInformation(h, ic, NULL, sz, &sz);
     if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
-        if(_E) {
+        if(IS_VALID_HANDLE(_E)) {
             rc = ACR_FROM_OS_ERROR(rc);
             if (ACR_STATUS_IS_EACCES(rc))
                 ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
@@ -183,7 +183,7 @@
                 rc = 0;
         }
         if (rc != ERROR_SUCCESS) {
-            if (_E) {
+            if (IS_VALID_HANDLE(_E)) {
                 if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
                     ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
                 else
@@ -199,15 +199,15 @@
 PSID ACR_AllocateWellKnownSid(JNIEnv *_E, WELL_KNOWN_SID_TYPE type)
 {
     DWORD ss = SECURITY_MAX_SID_SIZE;
-    PSID sid =  ACR_HeapMalloc(ss);
+    PSID sid = ACR_HMALLOC(SID, ss);
 
     if (sid) {
         if (!CreateWellKnownSid(type, NULL, sid, &ss)) {
             int ec = ACR_GET_OS_ERROR();
-            ACR_HeapFree(sid);
+            ACR_HFREE(sid);
             sid = NULL;
-            if (_E) {
-                if  (ACR_STATUS_IS_EACCES(ec))
+            if (IS_VALID_HANDLE(_E)) {
+                if (ACR_STATUS_IS_EACCES(ec))
                     ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
                 else
                     ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, ec);
@@ -597,10 +597,10 @@
         SECURITY_UNL();
         return _null_sa;
     }
-    _null_sa  = (PSECURITY_ATTRIBUTES)LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES));
+    _null_sa  = ACR_LALLOC(SECURITY_ATTRIBUTES, sizeof(SECURITY_ATTRIBUTES));
     _null_sa->nLength = sizeof(SECURITY_ATTRIBUTES);
 
-    pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+    pSD = ACR_LALLOC(SECURITY_DESCRIPTOR, SECURITY_DESCRIPTOR_MIN_LENGTH);
     _null_sa->lpSecurityDescriptor = pSD;
     if (pSD == NULL || _null_sa == NULL) {
         rc = ACR_ENOMEM;
@@ -622,12 +622,9 @@
     return _null_sa;
 
 cleanup:
-    if (pSD)
-        LocalFree(pSD);
-    if (_null_sa) {
-        LocalFree(_null_sa);
-        _null_sa = NULL;
-    }
+    ACR_LFREE(pSD);
+    ACR_LFREE(_null_sa);
+
     _null_sa = &_empty_sa;
     _null_sa->nLength = sizeof(SECURITY_ATTRIBUTES);
     _null_sa->lpSecurityDescriptor = NULL;



Mime
View raw message