Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak from HepPDT::HeavyIonUnknownID #25298

Merged
merged 2 commits into from Nov 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions SimGeneral/HepPDTESSource/BuildFile.xml
@@ -1,3 +1,4 @@
<use name="FWCore/ParameterSet"/>
<use name="SimGeneral/HepPDTRecord"/>
<use name="tbb"/>
<flags EDM_PLUGIN="1"/>
24 changes: 23 additions & 1 deletion SimGeneral/HepPDTESSource/src/HepPDTESSource.cc
@@ -1,5 +1,27 @@
#include "SimGeneral/HepPDTESSource/interface/HepPDTESSource.h"
#include "HepPDT/HeavyIonUnknownID.hh"
#include "tbb/concurrent_vector.h"

namespace {

class CachingHeavyIonUnknownID : public HepPDT::ProcessUnknownID {
HepPDT::ParticleData * processUnknownID( HepPDT::ParticleID id,
const HepPDT::ParticleDataTable & table) final {
//HeavyIonUnknownID constructs a new particle but does not delete it
// we need to do that ourselves
std::unique_ptr<HepPDT::ParticleData> p{ wrapped_.processUnknownID(id, table) };
auto* pPtr = p.get();
if(p) {
particles_.emplace_back(std::move(p));
}
return pPtr;
}

HepPDT::HeavyIonUnknownID wrapped_;
tbb::concurrent_vector<std::unique_ptr<HepPDT::ParticleData>> particles_;
};

}

HepPDTESSource::HepPDTESSource( const edm::ParameterSet& cfg ) :
pdtFileName( cfg.getParameter<edm::FileInPath>( "pdtFileName" ) ) {
Expand All @@ -13,7 +35,7 @@ HepPDTESSource::~HepPDTESSource() {
HepPDTESSource::ReturnType
HepPDTESSource::produce( const PDTRecord & iRecord ) {
using namespace edm::es;
auto pdt = std::make_unique<PDT>( "PDG table" , new HepPDT::HeavyIonUnknownID );
auto pdt = std::make_unique<PDT>( "PDG table" , new CachingHeavyIonUnknownID );
std::ifstream pdtFile( pdtFileName.fullPath().c_str() );
if( ! pdtFile )
throw cms::Exception( "FileNotFound", "can't open pdt file" )
Expand Down