fix(env.c): drop envmap, free os_getenv() result #32683

Problem:
vim.uv.os_setenv gets "stuck" per-key. #32550
Caused by the internal `envmap` cache. #7920

    :echo $FOO  <-- prints nothing
    :lua vim.uv.os_setenv("FOO", "bar")
    :echo $FOO  <-- prints bar (as expected)
    :lua vim.uv.os_setenv("FOO", "fizz")
    :echo $FOO  <-- prints bar, still (not expected. Should be "fizz")
    :lua vim.uv.os_unsetenv("FOO")
    :echo $FOO  <-- prints bar, still (not expected. Should be nothing)
    :lua vim.uv.os_setenv("FOO", "buzz")
    :echo $FOO  <-- prints bar, still (not expected. Should be "buzz")

Solution:
- Remove the `envmap` cache.
  - Callers to `os_getenv` must free the result.
- Update all call-sites.
- Introduce `os_getenv_noalloc`.
- Extend `os_env_exists()` the `nonempty` parameter.
This commit is contained in:
Judit Novak
2025-04-16 12:36:07 +02:00
committed by GitHub
parent 7432781e71
commit fd973c0a4e
26 changed files with 281 additions and 146 deletions

View File

@@ -2392,7 +2392,7 @@ bool path_is_absolute(const char *fname)
void path_guess_exepath(const char *argv0, char *buf, size_t bufsize)
FUNC_ATTR_NONNULL_ALL
{
const char *path = os_getenv("PATH");
char *path = os_getenv("PATH");
if (path == NULL || path_is_absolute(argv0)) {
xstrlcpy(buf, argv0, bufsize);
@@ -2427,4 +2427,5 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize)
// Not found in $PATH, fall back to argv0.
xstrlcpy(buf, argv0, bufsize);
}
xfree(path);
}