From 6fd6f4683d19d5ca18f48c1d1f0d87113e80368e Mon Sep 17 00:00:00 2001 From: erw7 Date: Mon, 21 Oct 2019 07:47:08 +0900 Subject: TUI/thread: guard env map from potential race with unibilium #11259 unibi_from_term calls getenv internally, so exclusive control is required. --- src/nvim/os/env.c | 10 ++++++++++ src/nvim/tui/tui.c | 2 ++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index ae61e54993..eb86cb8ac7 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -44,6 +44,16 @@ void env_init(void) uv_mutex_init(&mutex); } +void os_env_var_lock(void) +{ + uv_mutex_lock(&mutex); +} + +void os_env_var_unlock(void) +{ + uv_mutex_unlock(&mutex); +} + /// Like getenv(), but returns NULL if the variable is empty. /// @see os_env_exists const char *os_getenv(const char *name) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 150862bb18..945b093f32 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -234,7 +234,9 @@ static void terminfo_start(UI *ui) // Set up unibilium/terminfo. char *termname = NULL; if (term) { + os_env_var_lock(); data->ut = unibi_from_term(term); + os_env_var_unlock(); if (data->ut) { termname = xstrdup(term); } -- cgit