From 5f3508b4f3f12cec32945272f63620afca91a52a Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Fri, 24 Jul 2020 14:51:07 -0700 Subject: [PATCH] Member variable should not be a reference; causing crash when used in destructor. --- .../lb_policy/weighted_target/weighted_target.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc index 96491b68642..f1cfb73eadf 100644 --- a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +++ b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc @@ -169,7 +169,7 @@ class WeightedTargetLb : public LoadBalancingPolicy { // The owning LB policy. RefCountedPtr weighted_target_policy_; - const std::string& name_; + const std::string name_; uint32_t weight_; @@ -288,9 +288,8 @@ void WeightedTargetLb::UpdateLocked(UpdateArgs args) { const std::string& name = p.first; auto it = targets_.find(name); if (it == targets_.end()) { - it = targets_.emplace(std::make_pair(name, nullptr)).first; - it->second = MakeOrphanable( - Ref(DEBUG_LOCATION, "WeightedChild"), it->first); + targets_.emplace(name, MakeOrphanable( + Ref(DEBUG_LOCATION, "WeightedChild"), name)); } } // Update all children.