summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2022-05-20 19:56:19 -0600
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2022-05-24 14:18:26 -0600
commit2d1565377360833be414d49fc39c4d23f71a9f89 (patch)
treeb7d813928687b4f274ba655d0781ca994c5cce1f
parent9b355f194844ad4414816f283664f8b28819451a (diff)
downloadVulkan-Loader-2d1565377360833be414d49fc39c4d23f71a9f89.tar.gz
Vulkan-Loader-2d1565377360833be414d49fc39c4d23f71a9f89.tar.bz2
Vulkan-Loader-2d1565377360833be414d49fc39c4d23f71a9f89.zip
Use calloc instead of alloc+memset
Replace naked uses of malloc & free with loader_alloc & loader_free.
-rw-r--r--loader/loader.c26
-rw-r--r--loader/loader_linux.c5
-rw-r--r--loader/loader_windows.c8
-rw-r--r--loader/trampoline.c33
-rw-r--r--loader/wsi.c6
5 files changed, 34 insertions, 44 deletions
diff --git a/loader/loader.c b/loader/loader.c
index 98c5ff2e..3d95c0ac 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -338,13 +338,12 @@ static struct loader_layer_properties *loader_get_next_layer_property_slot(const
struct loader_layer_list *layer_list) {
if (layer_list->capacity == 0) {
layer_list->list =
- loader_instance_heap_alloc(inst, sizeof(struct loader_layer_properties) * 64, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ loader_instance_heap_calloc(inst, sizeof(struct loader_layer_properties) * 64, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (layer_list->list == NULL) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
"loader_get_next_layer_property_slot: Out of memory can not add any layer properties to list");
return NULL;
}
- memset(layer_list->list, 0, sizeof(struct loader_layer_properties) * 64);
layer_list->capacity = sizeof(struct loader_layer_properties) * 64;
}
@@ -641,12 +640,11 @@ VkResult loader_init_generic_list(const struct loader_instance *inst, struct loa
size_t capacity = 32 * element_size;
list_info->count = 0;
list_info->capacity = 0;
- list_info->list = loader_instance_heap_alloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ list_info->list = loader_instance_heap_calloc(inst, capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (list_info->list == NULL) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_init_generic_list: Failed to allocate space for generic list");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
- memset(list_info->list, 0, capacity);
list_info->capacity = capacity;
return VK_SUCCESS;
}
@@ -780,11 +778,10 @@ bool loader_add_meta_layer(const struct loader_instance *inst, const struct load
// Manage lists of VkLayerProperties
static bool loader_init_layer_list(const struct loader_instance *inst, struct loader_layer_list *list) {
list->capacity = 32 * sizeof(struct loader_layer_properties);
- list->list = loader_instance_heap_alloc(inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ list->list = loader_instance_heap_calloc(inst, list->capacity, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (list->list == NULL) {
return false;
}
- memset(list->list, 0, list->capacity);
list->count = 0;
return true;
}
@@ -1271,13 +1268,11 @@ static void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_i
static struct loader_icd_term *loader_icd_create(const struct loader_instance *inst) {
struct loader_icd_term *icd_term;
- icd_term = loader_instance_heap_alloc(inst, sizeof(struct loader_icd_term), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ icd_term = loader_instance_heap_calloc(inst, sizeof(struct loader_icd_term), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (!icd_term) {
return NULL;
}
- memset(icd_term, 0, sizeof(struct loader_icd_term));
-
return icd_term;
}
@@ -5712,15 +5707,14 @@ VkResult setup_loader_tramp_phys_devs(struct loader_instance *inst, uint32_t phy
// Something is different, so do the full path of checking every device and creating a new array to use.
// This can happen if a device was added, or removed, or we hadn't previously queried all the data and we
// have more to store.
- new_phys_devs = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_tramp *) * new_count,
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ new_phys_devs = loader_instance_heap_calloc(inst, sizeof(struct loader_physical_device_tramp *) * new_count,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (NULL == new_phys_devs) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
"setup_loader_tramp_phys_devs: Failed to allocate new physical device array of size %d", new_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(new_phys_devs, 0, sizeof(struct loader_physical_device_tramp *) * new_count);
if (new_count > phys_dev_count) {
found_count = phys_dev_count;
@@ -5981,15 +5975,14 @@ VkResult setup_loader_term_phys_devs(struct loader_instance *inst) {
}
// Create an allocation large enough to hold both the windows sorting enumeration and non-windows physical device enumeration
- new_phys_devs = loader_instance_heap_alloc(inst, sizeof(struct loader_physical_device_term *) * new_phys_devs_count,
- VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+ new_phys_devs = loader_instance_heap_calloc(inst, sizeof(struct loader_physical_device_term *) * new_phys_devs_count,
+ VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (NULL == new_phys_devs) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
"setup_loader_term_phys_devs: Failed to allocate new physical device array of size %d", new_phys_devs_count);
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(new_phys_devs, 0, sizeof(struct loader_physical_device_term *) * new_phys_devs_count);
// Current index into the new_phys_devs array - increment whenever we've written in.
uint32_t idx = 0;
@@ -6598,7 +6591,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDeviceGroups(
if (NULL != pPhysicalDeviceGroupProperties) {
// Create an array for the new physical device groups, which will be stored
// in the instance for the Terminator code.
- new_phys_dev_groups = (VkPhysicalDeviceGroupProperties **)loader_instance_heap_alloc(
+ new_phys_dev_groups = (VkPhysicalDeviceGroupProperties **)loader_instance_heap_calloc(
inst, total_count * sizeof(VkPhysicalDeviceGroupProperties *), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (NULL == new_phys_dev_groups) {
loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0,
@@ -6607,7 +6600,6 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_EnumeratePhysicalDeviceGroups(
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(new_phys_dev_groups, 0, total_count * sizeof(VkPhysicalDeviceGroupProperties *));
// Create a temporary array (on the stack) to keep track of the
// returned VkPhysicalDevice values.
diff --git a/loader/loader_linux.c b/loader/loader_linux.c
index 4df20134..cb4bcab1 100644
--- a/loader/loader_linux.c
+++ b/loader/loader_linux.c
@@ -238,13 +238,12 @@ VkResult linux_read_sorted_physical_devices(struct loader_instance *inst, uint32
VkResult res = VK_SUCCESS;
bool app_is_vulkan_1_1 = loader_check_version_meets_required(LOADER_VERSION_1_1_0, inst->app_api_version);
- struct LinuxSortedDeviceInfo *sorted_device_info =
- loader_instance_heap_alloc(inst, phys_dev_count * sizeof(struct LinuxSortedDeviceInfo), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
+ struct LinuxSortedDeviceInfo *sorted_device_info = loader_instance_heap_calloc(
+ inst, phys_dev_count * sizeof(struct LinuxSortedDeviceInfo), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (NULL == sorted_device_info) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(sorted_device_info, 0, phys_dev_count * sizeof(struct LinuxSortedDeviceInfo));
loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_DRIVER_BIT, 0, "linux_read_sorted_physical_devices:");
loader_log(inst, VULKAN_LOADER_INFO_BIT | VULKAN_LOADER_DRIVER_BIT, 0, " Original order:");
diff --git a/loader/loader_windows.c b/loader/loader_windows.c
index 27dcd73c..cc469a4e 100644
--- a/loader/loader_windows.c
+++ b/loader/loader_windows.c
@@ -804,15 +804,13 @@ VkResult windows_read_sorted_physical_devices(struct loader_instance *inst, uint
goto out;
}
sorted_alloc = 16;
- *sorted_devices =
- loader_instance_heap_alloc(inst, sorted_alloc * sizeof(struct loader_phys_dev_per_icd), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
+ *sorted_devices = loader_instance_heap_calloc(inst, sorted_alloc * sizeof(struct loader_phys_dev_per_icd),
+ VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (*sorted_devices == NULL) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
goto out;
}
- memset(*sorted_devices, 0, sorted_alloc * sizeof(struct loader_phys_dev_per_icd));
-
for (uint32_t i = 0;; ++i) {
IDXGIAdapter1 *adapter;
hres = dxgi_factory->lpVtbl->EnumAdapterByGpuPreference(dxgi_factory, i, DXGI_GPU_PREFERENCE_UNSPECIFIED,
@@ -998,4 +996,4 @@ VkResult windows_sort_physical_device_groups(struct loader_instance *inst, const
return VK_SUCCESS;
}
-#endif // _WIN32 \ No newline at end of file
+#endif // _WIN32
diff --git a/loader/trampoline.c b/loader/trampoline.c
index 4f34b84e..075b939c 100644
--- a/loader/trampoline.c
+++ b/loader/trampoline.c
@@ -164,11 +164,11 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
loader_scan_for_implicit_layers(NULL, &layers);
// We'll need to save the dl handles so we can close them later
- loader_platform_dl_handle *libs = malloc(sizeof(loader_platform_dl_handle) * layers.count);
+ loader_platform_dl_handle *libs =
+ loader_calloc(NULL, sizeof(loader_platform_dl_handle) * layers.count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (libs == NULL && layers.count > 0) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
- memset(libs, 0, sizeof(loader_platform_dl_handle) * layers.count);
size_t lib_count = 0;
// Prepend layers onto the chain if they implement this entry point
@@ -195,7 +195,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
continue;
}
- VkEnumerateInstanceExtensionPropertiesChain *chain_link = malloc(sizeof(VkEnumerateInstanceExtensionPropertiesChain));
+ VkEnumerateInstanceExtensionPropertiesChain *chain_link =
+ loader_alloc(NULL, sizeof(VkEnumerateInstanceExtensionPropertiesChain), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (chain_link == NULL) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
break;
@@ -222,14 +223,14 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
while (chain_head != &chain_tail) {
VkEnumerateInstanceExtensionPropertiesChain *holder = chain_head;
chain_head = (VkEnumerateInstanceExtensionPropertiesChain *)chain_head->pNextLink;
- free(holder);
+ loader_free(NULL, holder);
}
// Close the dl handles
for (size_t i = 0; i < lib_count; ++i) {
loader_platform_close_library(libs[i]);
}
- free(libs);
+ loader_free(NULL, libs);
return res;
}
@@ -258,8 +259,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
loader_scan_for_implicit_layers(NULL, &layers);
// We'll need to save the dl handles so we can close them later
- loader_platform_dl_handle *libs = malloc(sizeof(loader_platform_dl_handle) * layers.count);
- memset(libs, 0, sizeof(loader_platform_dl_handle) * layers.count);
+ loader_platform_dl_handle *libs =
+ loader_calloc(NULL, sizeof(loader_platform_dl_handle) * layers.count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (libs == NULL && layers.count > 0) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
@@ -289,7 +290,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
continue;
}
- VkEnumerateInstanceLayerPropertiesChain *chain_link = malloc(sizeof(VkEnumerateInstanceLayerPropertiesChain));
+ VkEnumerateInstanceLayerPropertiesChain *chain_link =
+ loader_alloc(NULL, sizeof(VkEnumerateInstanceLayerPropertiesChain), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (chain_link == NULL) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
break;
@@ -316,14 +318,14 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
while (chain_head != &chain_tail) {
VkEnumerateInstanceLayerPropertiesChain *holder = chain_head;
chain_head = (VkEnumerateInstanceLayerPropertiesChain *)chain_head->pNextLink;
- free(holder);
+ loader_free(NULL, holder);
}
// Close the dl handles
for (size_t i = 0; i < lib_count; ++i) {
loader_platform_close_library(libs[i]);
}
- free(libs);
+ loader_free(NULL, libs);
return res;
}
@@ -359,11 +361,11 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
loader_scan_for_implicit_layers(NULL, &layers);
// We'll need to save the dl handles so we can close them later
- loader_platform_dl_handle *libs = malloc(sizeof(loader_platform_dl_handle) * layers.count);
+ loader_platform_dl_handle *libs =
+ loader_calloc(NULL, sizeof(loader_platform_dl_handle) * layers.count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (libs == NULL && layers.count > 0) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
- memset(libs, 0, sizeof(loader_platform_dl_handle) * layers.count);
size_t lib_count = 0;
// Prepend layers onto the chain if they implement this entry point
@@ -388,7 +390,8 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
continue;
}
- VkEnumerateInstanceVersionChain *chain_link = malloc(sizeof(VkEnumerateInstanceVersionChain));
+ VkEnumerateInstanceVersionChain *chain_link =
+ loader_alloc(NULL, sizeof(VkEnumerateInstanceVersionChain), VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
if (chain_link == NULL) {
res = VK_ERROR_OUT_OF_HOST_MEMORY;
break;
@@ -415,14 +418,14 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
while (chain_head != &chain_tail) {
VkEnumerateInstanceVersionChain *holder = chain_head;
chain_head = (VkEnumerateInstanceVersionChain *)chain_head->pNextLink;
- free(holder);
+ loader_free(NULL, holder);
}
// Close the dl handles
for (size_t i = 0; i < lib_count; ++i) {
loader_platform_close_library(libs[i]);
}
- free(libs);
+ loader_free(NULL, libs);
return res;
}
diff --git a/loader/wsi.c b/loader/wsi.c
index 48d0adeb..23c589b1 100644
--- a/loader/wsi.c
+++ b/loader/wsi.c
@@ -528,13 +528,11 @@ static VkIcdSurface *AllocateIcdSurfaceStruct(struct loader_instance *instance,
pIcdSurface->non_platform_offset = (uint32_t)((uint8_t *)(&pIcdSurface->base_size) - (uint8_t *)pIcdSurface);
pIcdSurface->entire_size = sizeof(VkIcdSurface);
- pIcdSurface->real_icd_surfaces = loader_instance_heap_alloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
- VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ pIcdSurface->real_icd_surfaces = loader_instance_heap_calloc(instance, sizeof(VkSurfaceKHR) * instance->total_icd_count,
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (pIcdSurface->real_icd_surfaces == NULL) {
loader_instance_heap_free(instance, pIcdSurface);
pIcdSurface = NULL;
- } else {
- memset(pIcdSurface->real_icd_surfaces, 0, sizeof(VkSurfaceKHR) * instance->total_icd_count);
}
}
return pIcdSurface;