From 524eb03ff19be6f7837ed3cf9708ea9b77a947c9 Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Wed, 26 Aug 2020 10:23:02 -0700 Subject: [PATCH] [PATCH] Member variable should not be a reference; causing crash when used in destructor (backport into 1.30.x) Gbp-Pq: Name 16-member_variable_should_not_be_a_reference.patch --- .../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 96491b68..f1cfb73e 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. -- 2.30.2