From: Jeff Layton Date: Wed, 11 Oct 2017 15:16:38 +0000 (-0400) Subject: common: make it safe to call env_to_vec multiple times X-Git-Tag: v13.0.1~565^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=90e898de5f4b8d22f1a6d0e2aedf9e8c50cf72d5;p=ceph-ci.git common: make it safe to call env_to_vec multiple times After it has been called once and we have outstanding CephContexts with pointers into str_vec, we can't call get_str_vec on it again. Add a static local mutex to protect access to str_vec. Tracker: http://tracker.ceph.com/issues/21512 Signed-off-by: Jeff Layton --- diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 355224d0a84..7630d20322e 100644 --- a/src/common/ceph_argparse.cc +++ b/src/common/ceph_argparse.cc @@ -98,10 +98,20 @@ void env_to_vec(std::vector& args, const char *name) std::vector env_options; std::vector env_arguments; - static vector str_vec; std::vector env; - str_vec.clear(); - get_str_vec(p, " ", str_vec); + + static std::mutex str_vec_lock; + static vector str_vec; + + /* + * We can only populate str_vec once. Other threads could hold pointers into + * it, so clearing it out and replacing it is not currently safe. + */ + str_vec_lock.lock(); + if (str_vec.empty()) + get_str_vec(p, " ", str_vec); + str_vec_lock.unlock(); + for (vector::iterator i = str_vec.begin(); i != str_vec.end(); ++i)