From 8dec6175ab1167bab01af2594ac5d687072f3af2 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 11 Oct 2017 11:16:38 -0400 Subject: [PATCH] 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 (cherry picked from commit 90e898de5f4b8d22f1a6d0e2aedf9e8c50cf72d5) --- src/common/ceph_argparse.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/common/ceph_argparse.cc b/src/common/ceph_argparse.cc index 355224d0a84f0..7630d20322e4d 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) -- 2.39.5