Skip to content

Commit 76ecfc5

Browse files
authored
Merge pull request #48987 from Dr15Jones/lifetimeWriteConfigs
Fix lifetime issue found in edmWriteConfigs
2 parents 9bd0c17 + 236c475 commit 76ecfc5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

FWCore/ParameterSet/bin/edmWriteConfigs.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ int main(int argc, char** argv) try {
215215
edm::ParameterSetDescriptionFillerPluginFactory* factory;
216216
std::vector<std::string> pluginNames;
217217

218+
//The listener must live as long as any plugin might be loaded, which can happen while
219+
// writing plugins
220+
std::unique_ptr<Listener> listenerPtr;
218221
if (vm.count(kPluginOpt)) {
219222
edmplugin::PluginManager::configure(edmplugin::standard::config());
220223
factory = edm::ParameterSetDescriptionFillerPluginFactory::get();
@@ -245,10 +248,12 @@ int main(int argc, char** argv) try {
245248
} else {
246249
// the library name is part of a path
247250

248-
Listener listener;
251+
listenerPtr = std::make_unique<Listener>();
249252
edmplugin::PluginFactoryManager* pfm = edmplugin::PluginFactoryManager::get();
250-
pfm->newFactory_.connect(std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
251-
edm::for_all(*pfm, std::bind(std::mem_fn(&Listener::newFactory), &listener, _1));
253+
pfm->newFactory_.connect([&listenerPtr](auto const* factory) { listenerPtr->newFactory(factory); });
254+
for (auto& fact : *pfm) {
255+
listenerPtr->newFactory(fact);
256+
}
252257

253258
std::filesystem::path loadableFile(library);
254259

@@ -283,12 +288,15 @@ int main(int argc, char** argv) try {
283288

284289
factory = edm::ParameterSetDescriptionFillerPluginFactory::get();
285290

286-
edm::for_all(listener.nameAndTypes_,
287-
std::bind(&getPluginsMatchingCategory, _1, std::ref(pluginNames), std::cref(factory->category())));
291+
for (auto const& nt : listenerPtr->nameAndTypes_) {
292+
getPluginsMatchingCategory(nt, pluginNames, factory->category());
293+
}
288294
}
289295

290296
std::set<std::string> usedCfiFileNames;
291-
edm::for_all(pluginNames, std::bind(&writeCfisForPlugin, _1, factory, std::ref(usedCfiFileNames)));
297+
for (auto const& plugin : pluginNames) {
298+
writeCfisForPlugin(plugin, factory, usedCfiFileNames);
299+
}
292300
});
293301
} catch (cms::Exception& iException) {
294302
if (!library.empty()) {

0 commit comments

Comments
 (0)