Move library list allocation to out of layer search function
authorCharles Giessen <charles@lunarg.com>
Sat, 6 May 2023 03:28:50 +0000 (21:28 -0600)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Mon, 29 May 2023 23:45:08 +0000 (17:45 -0600)
The allocation of the library list shouldn't be happening in the call to
loader_scan_for_implicit_layers.

loader/loader.c
loader/loader.h
loader/trampoline.c

index 593cc754cf82dc0d974715e79df2d7c9ef937583..6b6661d1cde85e2289c4aa4eebc7b15291d0b394 100644 (file)
@@ -236,6 +236,16 @@ void loader_free_layer_properties(const struct loader_instance *inst, struct loa
     memset(layer_properties, 0, sizeof(struct loader_layer_properties));
 }
 
+VkResult loader_init_library_list(struct loader_layer_list *instance_layers, loader_platform_dl_handle **libs) {
+    if (instance_layers->count > 0) {
+        *libs = loader_calloc(NULL, sizeof(loader_platform_dl_handle) * instance_layers->count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
+        if (*libs == NULL) {
+            return VK_ERROR_OUT_OF_HOST_MEMORY;
+        }
+    }
+    return VK_SUCCESS;
+}
+
 // Combine path elements, separating each element with the platform-specific
 // directory separator, and save the combined string to a destination buffer,
 // not exceeding the given length. Path elements are given as variable args,
@@ -3968,8 +3978,7 @@ out:
     return res;
 }
 
-VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers,
-                                         loader_platform_dl_handle **libs) {
+VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers) {
     struct loader_envvar_filter enable_filter;
     struct loader_envvar_disable_layers_filter disable_filter;
     char *file_str;
@@ -4121,15 +4130,6 @@ VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct lo
         }
     }
 
-    // We'll need to save the dl handles so we can close them later
-    if (instance_layers->count > 0 && NULL != libs) {
-        *libs = loader_calloc(NULL, sizeof(loader_platform_dl_handle) * instance_layers->count, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND);
-        if (*libs == NULL) {
-            res = VK_ERROR_OUT_OF_HOST_MEMORY;
-            goto out;
-        }
-    }
-
 out:
 
     loader_instance_heap_free(inst, override_paths);
@@ -6887,7 +6887,7 @@ terminator_EnumerateInstanceExtensionProperties(const VkEnumerateInstanceExtensi
         loader_scanned_icd_clear(NULL, &icd_tramp_list);
 
         // Append enabled implicit layers.
-        res = loader_scan_for_implicit_layers(NULL, &instance_layers, NULL);
+        res = loader_scan_for_implicit_layers(NULL, &instance_layers);
         if (VK_SUCCESS != res) {
             goto out;
         }
index c037c7766d5d182147eaa6474a9652fbee5f9df9..7660f90fa9c76ee485517c7dc918109368062203 100644 (file)
@@ -97,6 +97,8 @@ void loader_initialize(void);
 void loader_release(void);
 void loader_preload_icds(void);
 void loader_unload_preloaded_icds(void);
+VkResult loader_init_library_list(struct loader_layer_list *instance_layers, loader_platform_dl_handle **libs);
+
 bool has_vk_extension_property_array(const VkExtensionProperties *vk_ext_prop, const uint32_t count,
                                      const VkExtensionProperties *ext_array);
 bool has_vk_extension_property(const VkExtensionProperties *vk_ext_prop, const struct loader_extension_list *ext_list);
@@ -130,8 +132,7 @@ VkResult loader_icd_scan(const struct loader_instance *inst, struct loader_icd_t
 void loader_icd_destroy(struct loader_instance *ptr_inst, struct loader_icd_term *icd_term,
                         const VkAllocationCallbacks *pAllocator);
 VkResult loader_scan_for_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers);
-VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers,
-                                         loader_platform_dl_handle **libs);
+VkResult loader_scan_for_implicit_layers(struct loader_instance *inst, struct loader_layer_list *instance_layers);
 VkResult loader_get_icd_loader_instance_extensions(const struct loader_instance *inst, struct loader_icd_tramp_list *icd_tramp_list,
                                                    struct loader_extension_list *inst_exts);
 struct loader_icd_term *loader_get_icd_and_device(const void *device, struct loader_device **found_dev, uint32_t *icd_index);
index f597af835a8b58b22abf834f8da6890b6b26bdab..7c468974b473b1a462be5b8fcff121135e99d110 100644 (file)
@@ -164,7 +164,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionPropert
     size_t lib_count = 0;
     memset(&layers, 0, sizeof(layers));
 
-    res = loader_scan_for_implicit_layers(NULL, &layers, &libs);
+    res = loader_scan_for_implicit_layers(NULL, &layers);
+    if (VK_SUCCESS != res) {
+        return res;
+    }
+
+    res = loader_init_library_list(&layers, &libs);
     if (VK_SUCCESS != res) {
         return res;
     }
@@ -257,7 +262,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(
     size_t lib_count = 0;
     memset(&layers, 0, sizeof(layers));
 
-    res = loader_scan_for_implicit_layers(NULL, &layers, &libs);
+    res = loader_scan_for_implicit_layers(NULL, &layers);
+    if (VK_SUCCESS != res) {
+        return res;
+    }
+
+    res = loader_init_library_list(&layers, &libs);
     if (VK_SUCCESS != res) {
         return res;
     }
@@ -357,7 +367,12 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceVersion(uint32_t
     size_t lib_count = 0;
     memset(&layers, 0, sizeof(layers));
 
-    res = loader_scan_for_implicit_layers(NULL, &layers, &libs);
+    res = loader_scan_for_implicit_layers(NULL, &layers);
+    if (VK_SUCCESS != res) {
+        return res;
+    }
+
+    res = loader_init_library_list(&layers, &libs);
     if (VK_SUCCESS != res) {
         return res;
     }