]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMap: fix stray option leak
authorSage Weil <sage@newdream.net>
Tue, 16 Feb 2021 21:50:18 +0000 (16:50 -0500)
committerSage Weil <sage@newdream.net>
Sun, 21 Feb 2021 13:52:31 +0000 (07:52 -0600)
The const Option* needs to remain alive only until the next clear().  Keep
the reference in ConfigMap and clean it up then.

Signed-off-by: Sage Weil <sage@newdream.net>
(cherry picked from commit 9397a46aec88e287d56a6286ed4319f65d9c1f31)

src/mon/ConfigMap.h
src/mon/ConfigMonitor.cc

index 71b725a40af0439ac29fca67621d134e16615026..d5991bc1d7f33b5d12e06a27d34a42a67bc74a19 100644 (file)
@@ -99,6 +99,7 @@ struct ConfigMap {
   Section global;
   std::map<std::string,Section, std::less<>> by_type;
   std::map<std::string,Section, std::less<>> by_id;
+  std::list<std::unique_ptr<Option>> stray_options;
 
   Section *find_section(const std::string& name) {
     if (name == "global") {
@@ -118,6 +119,7 @@ struct ConfigMap {
     global.clear();
     by_type.clear();
     by_id.clear();
+    stray_options.clear();
   }
   void dump(ceph::Formatter *f) const;
   std::map<std::string,std::string,std::less<>> generate_entity_map(
index 2d62c0ca521a8a822bdd67a4a8c95ce587188b4d..c316af3284e0f486248c831a70730fe950bdb89d 100644 (file)
@@ -810,8 +810,10 @@ void ConfigMonitor::load_config()
     }
     if (!opt) {
       dout(10) << __func__ << " unrecognized option '" << name << "'" << dendl;
-      opt = new Option(name, Option::TYPE_STR, Option::LEVEL_UNKNOWN);
-      // FIXME: this will be leaked!
+      config_map.stray_options.push_back(
+       std::unique_ptr<Option>(
+         new Option(name, Option::TYPE_STR, Option::LEVEL_UNKNOWN)));
+      opt = config_map.stray_options.back().get();
     }
 
     string err;