Skip to content

clear icd_tramp_list on error in EnumerateInstanceExtensionProperties - #2085

Merged
charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:inst-ext-enum-icd-list-clear
Oct 27, 2026
Merged

charles-lunarg merged 1 commit into
KhronosGroup:mainfrom
aizu-m:inst-ext-enum-icd-list-clear

Conversation

@aizu-m

@aizu-m aizu-m commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

LeakSanitizer, Linux Debug build with LOADER_ENABLE_ADDRESS_SANITIZER=ON, running the new test against the unpatched loader (loader kept mapped so its frames symbolise):

Direct leak of 8192 byte(s) in 2 object(s) allocated from:
    #0 0xffff903d709c in calloc
    #1 0xffff8bfb1eb4 in loader_calloc loader/allocation.c:48
    #2 0xffff8bfb235c in loader_instance_heap_calloc loader/allocation.c:94
    #3 0xffff8c086970 in normalize_path loader/loader.c:439
    #4 0xffff8c0870b0 in fixup_library_binary_path loader/loader.c:675
    #5 0xffff8c09769c in loader_scanned_icd_add loader/loader.c:2145
    #6 0xffff8c0a0648 in loader_icd_scan loader/loader.c:3752
    #7 0xffff8c0cc770 in terminator_EnumerateInstanceExtensionProperties loader/loader.c:7198
    #8 0xffff8c0cd1c0 in terminator_pre_instance_EnumerateInstanceExtensionProperties loader/loader.c:7258
    #9 0xffff8c0f662c in vkEnumerateInstanceExtensionProperties loader/trampoline.c:239
SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

Found while reading the cleanup labels in loader.c after the implicit layer scan fix in #2070. terminator_EnumerateInstanceExtensionProperties scans every installed driver into a local icd_tramp_list; each entry holds a dlopen handle and the driver's resolved path in lib_name. The success path releases that list with loader_clear_scanned_icd_list. The error paths jump to out:, which tears it down with loader_destroy_generic_list, and that frees only the array of entries. So when any driver returns an error from its vkEnumerateInstanceExtensionProperties (the two blocks above are one lib_name per installed driver), the paths and the library handles are lost on every call the application makes. vkCreateInstance already uses loader_clear_scanned_icd_list on its failure path for the same list. Use it at out: too; it is a no-op once the success path has cleared the list.

The test ICD gains enum_instance_extension_properties_return_code. EnumerateInstanceExtensionProperties.DriverExtensionQueryFails installs two drivers, makes the second fail its query, then resets the knob and checks the next call succeeds. LeakSanitizer flags it on the unpatched loader and it passes after the change; macOS leaks shows the same two blocks per call before and none after. Full suite green under ASAN on macOS (646/646), clang-format clean.

terminator_EnumerateInstanceExtensionProperties scans every driver into
a local icd_tramp_list, which dlopens each driver library and stores its
resolved path in lib_name. The success path releases that list with
loader_clear_scanned_icd_list, which closes the handles and frees the
paths. The error paths jump to out:, which tears the list down with
loader_destroy_generic_list instead. That frees only the array of
entries, so when a driver fails its instance extension query every
scanned driver's lib_name and library handle leak on each
vkEnumerateInstanceExtensionProperties call.

Use loader_clear_scanned_icd_list at out:, as the vkCreateInstance
failure path already does for the same list. It is a no-op once the
success path has cleared the list.

Add a test ICD knob so vkEnumerateInstanceExtensionProperties can fail,
and a regression test that runs through the failure path. On the
unpatched loader LeakSanitizer reports 8192 bytes in 2 allocations from
normalize_path via loader_scanned_icd_add and loader_icd_scan; it is
clean after the change.
@ci-tester-lunarg

Copy link
Copy Markdown

User aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg

Copy link
Copy Markdown

User aizu-m not on autobuild list. Waiting for curator authorization before starting CI build.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build queued with queue ID 172577.

@charles-lunarg charles-lunarg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an easy approve.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3914 running.

@ci-tester-lunarg

Copy link
Copy Markdown

CI Vulkan-Loader build # 3914 passed.

@charles-lunarg
charles-lunarg merged commit 698de0e into KhronosGroup:main Oct 27, 2026
96 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants