From 6fc2e798e63a2215f0a13f46a20d76e3592b7717 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 83bc6cc9a54..c1baca11258 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 @@ -171,7 +171,7 @@ class WeightedTargetLb : public LoadBalancingPolicy { // The owning LB policy. RefCountedPtr weighted_target_policy_; - const std::string& name_; + const std::string name_; uint32_t weight_; @@ -290,9 +290,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.