get_default_loader_name() cached the pointer returned by
getenv("HB_FACE_LOADER") for the process lifetime. That storage is
owned by the C runtime or the caller and may change or be freed after
the lookup, leaving the cached pointer dangling.
Duplicate the value on first use and hold onto the copy, rather than
caching the borrowed pointer or calling getenv() on every face load.
Use the existing hb_lazy_loader_t pattern (as static_face_loader_list
does): an unset or empty value, or an allocation failure, caches the
empty-string default; a non-empty value is copied with hb_malloc and
freed via hb_atexit.
Add an api smoke test that loads the fixture through the file and blob
default-loader entry points (loader == NULL) with HB_FACE_LOADER set,
then restores the caller's environment. Its value is LSan coverage of
the copy-and-free path in the asan-ubsan job; glibc's setenv() does not
free replaced strings, so the borrowed-pointer bug is not observable on
Linux. Verified: full meson test suite (275 tests) and test-face under
ASan/UBSan with leak detection enabled both pass.
Alternative to #6493, following review feedback there.
Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>