loader, icd: correct use of _aligned_malloc
authorMike Stroyan <mike@LunarG.com>
Tue, 6 Oct 2015 21:32:56 +0000 (15:32 -0600)
committerMike Stroyan <mike@LunarG.com>
Tue, 6 Oct 2015 22:39:11 +0000 (16:39 -0600)
Memory allocated with _aligned_malloc on WIN32 should be released with _aligned_free.
If icd/common/icd-instance is ever used on WIN32 it will now use _aligned_free.

loader_aligned_heap_alloc and loader_aligned_alloc would require additional
matching loader_aligned*_free functions to be correct for WIN32.
But both functions are never used.  Just remove those functions for now.

icd/common/icd-instance.c
loader/loader.c
loader/loader.h
loader/vk_loader_platform.h

index 3568b76..b792048 100644 (file)
@@ -58,7 +58,11 @@ static void * VKAPI default_alloc(void *user_data, size_t size,
 
 static void VKAPI default_free(void *user_data, void *ptr)
 {
+#if defined(_WIN32)
+    _aligned_free(ptr);
+#else
     free(ptr);
+#endif
 }
 
 struct icd_instance *icd_instance_create(const VkApplicationInfo *app_info,
index 9b9455c..1ffcc68 100644 (file)
@@ -118,22 +118,6 @@ void* loader_heap_alloc(
     return malloc(size);
 }
 
-void* loader_aligned_heap_alloc(
-    const struct loader_instance *instance,
-    size_t                        size,
-    size_t                        alignment,
-    VkSystemAllocType             alloc_type)
-{
-    if (instance && instance->alloc_callbacks.pfnAlloc) {
-        return instance->alloc_callbacks.pfnAlloc(instance->alloc_callbacks.pUserData, size, alignment, alloc_type);
-    }
-#if defined(_WIN32)
-    return _aligned_malloc(alignment, size);
-#else
-    return aligned_alloc(alignment, size);
-#endif
-}
-
 void loader_heap_free(
     const struct loader_instance   *instance,
     void                           *pMem)
index e27f18c..e96df3e 100644 (file)
@@ -394,12 +394,6 @@ void* loader_heap_alloc(
         size_t                       size,
         VkSystemAllocType            allocType);
 
-void* loader_aligned_heap_alloc(
-        const struct loader_instance *instance,
-        size_t                       size,
-        size_t                       alignment,
-        VkSystemAllocType            allocType);
-
 void loader_heap_free(
         const struct loader_instance *instance,
         void                         *pMem);
index 9602156..dd870dd 100644 (file)
@@ -203,7 +203,6 @@ static inline void loader_platform_thread_cond_broadcast(loader_platform_thread_
 }
 
 #define loader_stack_alloc(size) alloca(size)
-static inline void *loader_aligned_alloc(size_t alignment, size_t size) { void *ptr; posix_memalign(&ptr, alignment, size); return ptr; }
 
 #elif defined(_WIN32) // defined(__linux__)
 /* Windows-specific common code: */
@@ -448,7 +447,6 @@ char *loader_get_registry_string(const HKEY hive,
 #define DeleteCriticalSection PLEASE USE THE loader_platform_thread_delete_mutex() FUNCTION
 
 #define loader_stack_alloc(size) _alloca(size)
-static inline void *loader_aligned_alloc(size_t alignment, size_t size) { return _aligned_malloc(alignment, size); }
 
 #endif // defined(_WIN32)
 #endif /* LOADER_PLATFORM_H_TEMP */