[PATCH] Member variable should not be a reference; causing crash when used in destruc...
authorDonna Dionne <donnadionne@google.com>
Wed, 26 Aug 2020 17:23:02 +0000 (10:23 -0700)
committerLaszlo Boszormenyi (GCS) <gcs@debian.org>
Sun, 25 Sep 2022 18:03:42 +0000 (19:03 +0100)
Gbp-Pq: Name 16-member_variable_should_not_be_a_reference.patch

src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc

index 96491b686420a3bb82dc43fd16b0af2b59ca12d5..f1cfb73eadfc75760a44285e0730593603263f60 100644 (file)
@@ -169,7 +169,7 @@ class WeightedTargetLb : public LoadBalancingPolicy {
     // The owning LB policy.
     RefCountedPtr<WeightedTargetLb> 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<WeightedChild>(
-          Ref(DEBUG_LOCATION, "WeightedChild"), it->first);
+      targets_.emplace(name, MakeOrphanable<WeightedChild>(
+                                 Ref(DEBUG_LOCATION, "WeightedChild"), name));
     }
   }
   // Update all children.