Skip to content

Commit

Permalink
Adding deletes for heap variables
Browse files Browse the repository at this point in the history
"And I ain't never called malloc without calling free!" -- Monzy
  • Loading branch information
Alexander Gude committed May 8, 2014
1 parent d5ebc4f commit 0c26969
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ZFinder/Event/interface/ZFinderEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace zf {
const edm::EventSetup& iSetup,
const edm::ParameterSet& iConfig
);
// Destructor
~ZFinderEvent();

// Data or MC
bool is_real_data;
Expand Down
14 changes: 14 additions & 0 deletions ZFinder/Event/src/ZFinder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ ZFinder::ZFinder(const edm::ParameterSet& iConfig) : iConfig_(iConfig) {
ZFinder::~ZFinder() {
// do anything here that needs to be done at destruction time
// (e.g. close files, deallocate resources etc.)

// Delete our heap variables
for (auto& i_set : setters_) {
delete i_set;
}
for (auto& i_zdef : zdefs_) {
delete i_zdef;
}
for (auto& i_zdefp : zdef_plotters_) {
delete i_zdefp;
}
for (auto& i_zdefw : zdef_workspaces_) {
delete i_zdefw;
}
}


Expand Down
13 changes: 13 additions & 0 deletions ZFinder/Event/src/ZFinderEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,17 @@ namespace zf {
return false;
}
}

ZFinderEvent::~ZFinderEvent() {
// Clean up all the heap variables we have declared
for (auto& i_elec : reco_electrons_) {
delete i_elec;
}
for (auto& i_elec : hlt_electrons_) {
delete i_elec;
}
for (auto& i_elec : truth_electrons_) {
delete i_elec;
}
}
} // namespace zf

0 comments on commit 0c26969

Please sign in to comment.