Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/Vulkan-Loader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2022-08-24 20:30:00 +0300
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2022-09-01 22:13:14 +0300
commitad5c8f53050c7ce7c739823c4e13ab1f345d6111 (patch)
tree9c5009c3788032c5c4e6e5f8f78cfc282db81a41
parentb437061de1ce0df273d173472433e125a6e24ed7 (diff)
Remove redundant checks for NULL
Calling free() doesn't require checking for NULL, but many places were checking for NULL before calling the appropriate freeing function.
-rw-r--r--loader/extension_manual.c4
-rw-r--r--loader/loader.c122
-rw-r--r--loader/loader_linux.c4
-rw-r--r--loader/loader_windows.c24
-rw-r--r--loader/trampoline.c4
5 files changed, 36 insertions, 122 deletions
diff --git a/loader/extension_manual.c b/loader/extension_manual.c
index bfa28510a..196df20b1 100644
--- a/loader/extension_manual.c
+++ b/loader/extension_manual.c
@@ -384,9 +384,7 @@ out:
*pToolCount = 0;
}
- if (ext_props) {
- loader_instance_heap_free(icd_term->this_instance, ext_props);
- }
+ loader_instance_heap_free(icd_term->this_instance, ext_props);
return res;
}
diff --git a/loader/loader.c b/loader/loader.c
index fbc47917c..6e48e4466 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -199,18 +199,10 @@ VKAPI_ATTR VkResult VKAPI_CALL vkSetDeviceDispatch(VkDevice device, void *object
}
void loader_free_layer_properties(const struct loader_instance *inst, struct loader_layer_properties *layer_properties) {
- if (layer_properties->component_layer_names) {
- loader_instance_heap_free(inst, layer_properties->component_layer_names);
- }
- if (layer_properties->override_paths) {
- loader_instance_heap_free(inst, layer_properties->override_paths);
- }
- if (layer_properties->blacklist_layer_names) {
- loader_instance_heap_free(inst, layer_properties->blacklist_layer_names);
- }
- if (layer_properties->app_key_paths) {
- loader_instance_heap_free(inst, layer_properties->app_key_paths);
- }
+ loader_instance_heap_free(inst, layer_properties->component_layer_names);
+ loader_instance_heap_free(inst, layer_properties->override_paths);
+ loader_instance_heap_free(inst, layer_properties->blacklist_layer_names);
+ loader_instance_heap_free(inst, layer_properties->app_key_paths);
loader_destroy_generic_list(inst, (struct loader_generic_list *)&layer_properties->instance_extension_list);
@@ -1643,11 +1635,7 @@ static VkResult loader_get_json(const struct loader_instance *inst, const char *
size_t len;
VkResult res = VK_SUCCESS;
- if (NULL == json) {
- loader_log(inst, VULKAN_LOADER_ERROR_BIT, 0, "loader_get_json: Received invalid JSON file");
- res = VK_ERROR_INITIALIZATION_FAILED;
- goto out;
- }
+ assert(json != NULL);
*json = NULL;
@@ -1705,9 +1693,7 @@ static VkResult loader_get_json(const struct loader_instance *inst, const char *
}
out:
- if (NULL != json_buf) {
- loader_instance_heap_free(inst, json_buf);
- }
+ loader_instance_heap_free(inst, json_buf);
if (NULL != file) {
fclose(file);
}
@@ -2659,9 +2645,7 @@ static VkResult loader_add_layer_properties(const struct loader_instance *inst,
}
out:
- if (NULL != file_vers) {
- loader_instance_heap_free(inst, file_vers);
- }
+ loader_instance_heap_free(inst, file_vers);
return result;
}
@@ -2914,10 +2898,6 @@ static VkResult read_data_files_in_search_paths(const struct loader_instance *in
bool use_first_found_manifest = false;
#ifndef _WIN32
size_t rel_size = 0; // unused in windows, dont declare so no compiler warnings are generated
- bool xdg_config_home_secenv_alloc = true;
- bool xdg_config_dirs_secenv_alloc = true;
- bool xdg_data_home_secenv_alloc = true;
- bool xdg_data_dirs_secenv_alloc = true;
#endif
#if defined(_WIN32)
@@ -2926,14 +2906,8 @@ static VkResult read_data_files_in_search_paths(const struct loader_instance *in
// Determine how much space is needed to generate the full search path
// for the current manifest files.
char *xdg_config_home = loader_secure_getenv("XDG_CONFIG_HOME", inst);
- if (NULL == xdg_config_home) {
- xdg_config_home_secenv_alloc = false;
- }
-
char *xdg_config_dirs = loader_secure_getenv("XDG_CONFIG_DIRS", inst);
- if (NULL == xdg_config_dirs) {
- xdg_config_dirs_secenv_alloc = false;
- }
+
#if !defined(__Fuchsia__) && !defined(__QNXNTO__)
if (NULL == xdg_config_dirs || '\0' == xdg_config_dirs[0]) {
xdg_config_dirs = FALLBACK_CONFIG_DIRS;
@@ -2941,14 +2915,8 @@ static VkResult read_data_files_in_search_paths(const struct loader_instance *in
#endif
char *xdg_data_home = loader_secure_getenv("XDG_DATA_HOME", inst);
- if (NULL == xdg_data_home) {
- xdg_data_home_secenv_alloc = false;
- }
-
char *xdg_data_dirs = loader_secure_getenv("XDG_DATA_DIRS", inst);
- if (NULL == xdg_data_dirs) {
- xdg_data_dirs_secenv_alloc = false;
- }
+
#if !defined(__Fuchsia__) && !defined(__QNXNTO__)
if (NULL == xdg_data_dirs || '\0' == xdg_data_dirs[0]) {
xdg_data_dirs = FALLBACK_DATA_DIRS;
@@ -3233,46 +3201,22 @@ static VkResult read_data_files_in_search_paths(const struct loader_instance *in
out:
- if (NULL != additional_env) {
- loader_free_getenv(additional_env, inst);
- }
- if (NULL != override_env) {
- loader_free_getenv(override_env, inst);
- }
+ loader_free_getenv(additional_env, inst);
+ loader_free_getenv(override_env, inst);
#if defined(_WIN32)
- if (NULL != package_path) {
- loader_instance_heap_free(inst, package_path);
- }
+ loader_instance_heap_free(inst, package_path);
#else
- if (xdg_config_home_secenv_alloc) {
- loader_free_getenv(xdg_config_home, inst);
- }
- if (xdg_config_dirs_secenv_alloc) {
- loader_free_getenv(xdg_config_dirs, inst);
- }
- if (xdg_data_home_secenv_alloc) {
- loader_free_getenv(xdg_data_home, inst);
- }
- if (xdg_data_dirs_secenv_alloc) {
- loader_free_getenv(xdg_data_dirs, inst);
- }
- if (NULL != xdg_data_home) {
- loader_free_getenv(xdg_data_home, inst);
- }
- if (NULL != home) {
- loader_free_getenv(home, inst);
- }
- if (NULL != default_data_home) {
- loader_instance_heap_free(inst, default_data_home);
- }
- if (NULL != default_config_home) {
- loader_instance_heap_free(inst, default_config_home);
- }
+ loader_free_getenv(xdg_config_home, inst);
+ loader_free_getenv(xdg_config_dirs, inst);
+ loader_free_getenv(xdg_data_home, inst);
+ loader_free_getenv(xdg_data_dirs, inst);
+ loader_free_getenv(xdg_data_home, inst);
+ loader_free_getenv(home, inst);
+ loader_instance_heap_free(inst, default_data_home);
+ loader_instance_heap_free(inst, default_config_home);
#endif
- if (NULL != search_path) {
- loader_instance_heap_free(inst, search_path);
- }
+ loader_instance_heap_free(inst, search_path);
return vk_result;
}
@@ -3654,9 +3598,7 @@ out:
if (NULL != manifest_files.filename_list) {
for (uint32_t i = 0; i < manifest_files.count; i++) {
- if (NULL != manifest_files.filename_list[i]) {
- loader_instance_heap_free(inst, manifest_files.filename_list[i]);
- }
+ loader_instance_heap_free(inst, manifest_files.filename_list[i]);
}
loader_instance_heap_free(inst, manifest_files.filename_list);
}
@@ -3788,14 +3730,10 @@ void loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_li
out:
- if (NULL != override_paths) {
- loader_instance_heap_free(inst, override_paths);
- }
+ loader_instance_heap_free(inst, override_paths);
if (NULL != manifest_files.filename_list) {
for (uint32_t i = 0; i < manifest_files.count; i++) {
- if (NULL != manifest_files.filename_list[i]) {
- loader_instance_heap_free(inst, manifest_files.filename_list[i]);
- }
+ loader_instance_heap_free(inst, manifest_files.filename_list[i]);
}
loader_instance_heap_free(inst, manifest_files.filename_list);
}
@@ -3933,17 +3871,11 @@ void loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader
out:
- if (NULL != override_paths) {
- loader_instance_heap_free(inst, override_paths);
- }
+ loader_instance_heap_free(inst, override_paths);
for (uint32_t i = 0; i < manifest_files.count; i++) {
- if (NULL != manifest_files.filename_list[i]) {
- loader_instance_heap_free(inst, manifest_files.filename_list[i]);
- }
- }
- if (NULL != manifest_files.filename_list) {
- loader_instance_heap_free(inst, manifest_files.filename_list);
+ loader_instance_heap_free(inst, manifest_files.filename_list[i]);
}
+ loader_instance_heap_free(inst, manifest_files.filename_list);
if (have_json_lock) {
loader_platform_thread_unlock_mutex(&loader_json_lock);
diff --git a/loader/loader_linux.c b/loader/loader_linux.c
index cb4bcab11..4a31da623 100644
--- a/loader/loader_linux.c
+++ b/loader/loader_linux.c
@@ -338,9 +338,7 @@ VkResult linux_read_sorted_physical_devices(struct loader_instance *inst, uint32
}
out:
- if (NULL != sorted_device_info) {
- loader_instance_heap_free(inst, sorted_device_info);
- }
+ loader_instance_heap_free(inst, sorted_device_info);
return res;
}
diff --git a/loader/loader_windows.c b/loader/loader_windows.c
index 693b6b7a3..4015acbb8 100644
--- a/loader/loader_windows.c
+++ b/loader/loader_windows.c
@@ -220,9 +220,7 @@ bool windows_get_device_registry_entry(const struct loader_instance *inst, char
found = windows_add_json_entry(inst, reg_data, total_size, value_name, data_type, manifest_path, requiredSize, result);
out:
- if (manifest_path != NULL) {
- loader_instance_heap_free(inst, manifest_path);
- }
+ loader_instance_heap_free(inst, manifest_path);
RegCloseKey(hkrKey);
return found;
}
@@ -255,9 +253,7 @@ VkResult windows_get_device_registry_files(const struct loader_instance *inst, u
do {
CM_Get_Device_ID_List_SizeW(&deviceNamesSize, displayGUID, flags);
- if (pDeviceNames != NULL) {
- loader_instance_heap_free(inst, pDeviceNames);
- }
+ loader_instance_heap_free(inst, pDeviceNames);
pDeviceNames = loader_instance_heap_alloc(inst, deviceNamesSize * sizeof(wchar_t), VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
if (pDeviceNames == NULL) {
@@ -692,15 +688,9 @@ VkResult windows_read_manifest_from_d3d_adapters(const struct loader_instance *i
}
out:
- if (json_path != NULL) {
- loader_instance_heap_free(inst, json_path);
- }
- if (full_info != NULL) {
- loader_instance_heap_free(inst, full_info);
- }
- if (adapters.adapters != NULL) {
- loader_instance_heap_free(inst, adapters.adapters);
- }
+ loader_instance_heap_free(inst, json_path);
+ loader_instance_heap_free(inst, full_info);
+ loader_instance_heap_free(inst, adapters.adapters);
return result;
}
@@ -788,9 +778,7 @@ VkResult windows_read_data_files_in_registry(const struct loader_instance *inst,
out:
- if (NULL != search_path) {
- loader_instance_heap_free(inst, search_path);
- }
+ loader_instance_heap_free(inst, search_path);
return vk_result;
}
diff --git a/loader/trampoline.c b/loader/trampoline.c
index 274b16696..d65e7b1ec 100644
--- a/loader/trampoline.c
+++ b/loader/trampoline.c
@@ -615,9 +615,7 @@ out:
if (loader.instances == ptr_instance) {
loader.instances = ptr_instance->next;
}
- if (NULL != ptr_instance->disp) {
- loader_instance_heap_free(ptr_instance, ptr_instance->disp);
- }
+ loader_instance_heap_free(ptr_instance, ptr_instance->disp);
// Remove any created VK_EXT_debug_report or VK_EXT_debug_utils items
destroy_debug_callbacks_chain(ptr_instance, pAllocator);