]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/ConfigMap: fix stray option leak 40299/head
authorSage Weil <sage@newdream.net>
Tue, 16 Feb 2021 21:50:18 +0000 (16:50 -0500)
committerKefu Chai <kchai@redhat.com>
Mon, 22 Mar 2021 05:54:36 +0000 (13:54 +0800)
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)

Fixes: https://tracker.ceph.com/issues/48381
Conflicts:
src/mon/ConfigMap.h: trivial resolution

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

index 220715256fd502630deae328d6f0a3f37300be2b..dd4679751808755d6da6730803661048522e4e91 100644 (file)
@@ -99,6 +99,7 @@ struct ConfigMap {
   Section global;
   std::map<std::string,Section> by_type;
   std::map<std::string,Section> 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(Formatter *f) const;
   void generate_entity_map(
index ae7bda2fb53f81189dcdad11fa63861d8e73e5d7..12e0a337dfeb01ae3337fca96d22676786e90952 100644 (file)
@@ -755,8 +755,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;