mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
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:
@@ -938,12 +938,11 @@ static void remote_request(mparm_T *params, int remote_args, char *server_addr,
|
||||
if (!chan) {
|
||||
fprintf(stderr, "Remote ui failed to start: %s\n", connect_error);
|
||||
os_exit(1);
|
||||
} else if (strequal(server_addr, os_getenv("NVIM"))) {
|
||||
} else if (strequal(server_addr, os_getenv_noalloc("NVIM"))) {
|
||||
fprintf(stderr, "%s", "Cannot attach UI of :terminal child to its parent. ");
|
||||
fprintf(stderr, "%s\n", "(Unset $NVIM to skip this check)");
|
||||
os_exit(1);
|
||||
}
|
||||
|
||||
ui_client_channel_id = chan;
|
||||
return;
|
||||
}
|
||||
@@ -2118,7 +2117,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
|
||||
static int execute_env(char *env)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
const char *initstr = os_getenv(env);
|
||||
char *initstr = os_getenv(env);
|
||||
if (initstr == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
@@ -2132,6 +2131,8 @@ static int execute_env(char *env)
|
||||
|
||||
estack_pop();
|
||||
current_sctx = save_current_sctx;
|
||||
|
||||
xfree(initstr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user