From 2537fe0f9e988c0390ef2afecaf69ab223b95ca6 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 13 Apr 2019 11:54:02 -0700 Subject: [PATCH] Put back a missing lock in env_stack_t::set_internal Setting a variable could race with getting it. The lockin^g here needs a serious overhaul. --- src/env.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/env.cpp b/src/env.cpp index 729f982bc..918666fd5 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -95,6 +95,9 @@ class env_node_t { using env_node_ref_t = std::shared_ptr; +// This is a big dorky lock we take around everything that might modify an env_node_t. Fine grained +// locking is annoying here because env_nodes may be shared between env_stacks, so each node would +// need its own lock. static std::mutex env_lock; // A class wrapping up a variable stack @@ -631,6 +634,7 @@ int env_stack_t::set_internal(const wcstring &key, env_mode_flags_t input_var_mo env_set_internal_universal(key, std::move(val), var_mode, this); } } else { + scoped_lock locker(env_lock); // Determine the node. bool has_changed_new = false; env_node_ref_t preexisting_node = get_node(key);