From 492a05fec2d6a736ba11d650a8890aaca843e83b Mon Sep 17 00:00:00 2001 From: Piotr Date: Wed, 29 Jan 2014 11:13:07 +0100 Subject: [PATCH] memory leak fixes --- .../DTSegment/src/DTMeantimerPatternReco.cc | 3 +++ .../DTSegment/src/DTMeantimerPatternReco4D.cc | 22 +++++++++++-------- .../DTSegment/src/DTMeantimerPatternReco4D.h | 3 ++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco.cc b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco.cc index b2cdc73dcde40..967d600556888 100644 --- a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco.cc +++ b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco.cc @@ -77,6 +77,9 @@ DTMeantimerPatternReco::reconstruct(const DTSuperLayer* sl, delete *(cand++); // delete the candidate! } + for (vector::iterator it = hitsForFit.begin(), ed = hitsForFit.end(); + it != ed; ++it) delete *it; + return result; } diff --git a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc index b471903ecb536..16f11a35bbc73 100644 --- a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc +++ b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc @@ -54,8 +54,7 @@ DTMeantimerPatternReco4D::DTMeantimerPatternReco4D(const ParameterSet& pset): // Get the concrete 2D-segments reconstruction algo from the factory // For the 2D reco I use this reconstructor! the2DAlgo = new DTMeantimerPatternReco(pset.getParameter("Reco2DAlgoConfig")); - - } +} DTMeantimerPatternReco4D::~DTMeantimerPatternReco4D(){ @@ -134,7 +133,9 @@ DTMeantimerPatternReco4D::reconstruct(){ cout << "Segments in " << theChamber->id() << endl; cout << "Reconstructing Phi segments"< resultPhi = buildPhiSuperSegmentsCandidates(); + + vector pairPhiOwned; + vector resultPhi = buildPhiSuperSegmentsCandidates(pairPhiOwned); if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl; @@ -158,7 +159,7 @@ DTMeantimerPatternReco4D::reconstruct(){ hasZed = theSegments2DTheta.size()>0; if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl; } else { - if (debug) cout << "No Theta SL" << endl; + if (debug) cout << "No Theta candidates." << endl; } // Now I want to build the concrete DTRecSegment4D. @@ -167,9 +168,10 @@ DTMeantimerPatternReco4D::reconstruct(){ for (vector::const_iterator phi=resultPhi.begin(); phi!=resultPhi.end(); ++phi) { - DTChamberRecSegment2D* superPhi = (**phi); + std::auto_ptr superPhi(**phi); - theUpdator->update(superPhi); + theUpdator->update(superPhi.get()); + if(debug) cout << "superPhi: " << *superPhi << endl; if (hasZed) { @@ -195,7 +197,6 @@ DTMeantimerPatternReco4D::reconstruct(){ const LocalVector dirZInCh = theChamber->toLocal( zSL->toGlobal(zed->localDirection())); DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi,*zed,posZInCh,dirZInCh); - //<< /// 4d segment: I have the pos along the wire => further update! theUpdator->update(newSeg); @@ -247,13 +248,15 @@ DTMeantimerPatternReco4D::reconstruct(){ // finally delete the candidates! for (vector::iterator phi=resultPhi.begin(); phi!=resultPhi.end(); ++phi) delete *phi; + for (vector::iterator phiPair = pairPhiOwned.begin(); + phiPair!=pairPhiOwned.end(); ++phiPair) delete *phiPair; return result; } -vector DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates(){ +vector DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates(vector &pairPhiOwned){ DTSuperLayerId slId; @@ -276,6 +279,7 @@ vector DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates // copy the pairPhi2 in the pairPhi1 vector copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1)); + pairPhiOwned.swap(pairPhi1); // Build the segment candidate - return the2DAlgo->buildSegments(sl,pairPhi1); + return the2DAlgo->buildSegments(sl,pairPhiOwned); } diff --git a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.h b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.h index f7a8c713ec01c..7ab28a8b568d8 100644 --- a/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.h +++ b/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.h @@ -33,6 +33,7 @@ class DTSegmentUpdator; // ====================================================================== class DTSegmentCand; class DTMeantimerPatternReco; +class DTHitPairForFit; // Class DTMeantimerPatternReco4D Interface @@ -60,7 +61,7 @@ class DTMeantimerPatternReco4D : public DTRecSegment4DBaseAlgo { protected: private: - std::vector buildPhiSuperSegmentsCandidates(); + std::vector buildPhiSuperSegmentsCandidates(std::vector &pairPhiOwned); DTRecSegment4D* segmentSpecialZed(DTRecSegment4D* seg);