From 56d16982b13bcf3cc74c12e705169c40ef5167bf Mon Sep 17 00:00:00 2001 From: "Stephen A. Wood" <saw@jlab.org> Date: Fri, 5 Sep 2014 14:51:55 -0400 Subject: [PATCH] Minor memory leak squashing. (From running valgrind) --- src/THcDC.cxx | 2 ++ src/THcDetectorMap.cxx | 1 + src/THcHodoscope.cxx | 1 + src/THcParmList.cxx | 11 +++++++++-- src/THcShower.cxx | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/THcDC.cxx b/src/THcDC.cxx index 9bd76b2..5ba6fb2 100644 --- a/src/THcDC.cxx +++ b/src/THcDC.cxx @@ -157,6 +157,8 @@ void THcDC::Setup(const char* name, const char* description) cout << "Created Drift Chamber " << i+1 << ", " << desc1 << endl; newchamber->SetHMSStyleFlag(fHMSStyleChambers); // Tell the chamber its style } + delete [] desc; + delete [] desc1; } //_____________________________________________________________________________ diff --git a/src/THcDetectorMap.cxx b/src/THcDetectorMap.cxx index a4ff120..c6d25a0 100644 --- a/src/THcDetectorMap.cxx +++ b/src/THcDetectorMap.cxx @@ -315,6 +315,7 @@ void THcDetectorMap::Load(const char *fname) if(nvals==4) { signal= ((TObjString*)vararr->At(3))->GetString().Atoi(); } + delete vararr; // Discard result of Tokenize fTable[fNchans].roc=roc; fTable[fNchans].slot=slot; diff --git a/src/THcHodoscope.cxx b/src/THcHodoscope.cxx index bf4b47e..7e7aee9 100644 --- a/src/THcHodoscope.cxx +++ b/src/THcHodoscope.cxx @@ -133,6 +133,7 @@ void THcHodoscope::Setup(const char* name, const char* description) fPlanes[i] = new THcScintillatorPlane(fPlaneNames[i], desc, i+1,fNPlanes,this); // Number planes starting from zero!! cout << "Created Scintillator Plane " << fPlaneNames[i] << ", " << desc << endl; } + delete [] desc; } //_____________________________________________________________________________ diff --git a/src/THcParmList.cxx b/src/THcParmList.cxx index b0ae38b..56d46c4 100644 --- a/src/THcParmList.cxx +++ b/src/THcParmList.cxx @@ -135,12 +135,12 @@ void THcParmList::Load( const char* fname, Int_t RunNumber ) current_comment.assign(line,pos+1,line.length()); line.erase(pos); // Strip off comment // Strip leading white space from comment - cout << "CommentA: " << current_comment << endl; + //cout << "CommentA: " << current_comment << endl; pos = current_comment.find_first_not_of(whtspc); if(pos!=string::npos && pos > 0 && pos < current_comment.length()) { current_comment.erase(0,pos); } - cout << "CommentB: " << current_comment << endl; + //cout << "CommentB: " << current_comment << endl; break; } } @@ -348,6 +348,11 @@ void THcParmList::Load( const char* fname, Int_t RunNumber ) } currentindex += nvals; // Remove old variable and recreate + if(existingtype == kDouble) { + delete [] (Double_t*) existingvar->GetValuePointer(); + } else if (existingtype == kInt) { + delete [] (Int_t*) existingvar->GetValuePointer(); + } RemoveName(varname); char *arrayname=new char [strlen(varname)+20]; sprintf(arrayname,"%s[%d]",varname,newlength); @@ -417,6 +422,8 @@ void THcParmList::Load( const char* fname, Int_t RunNumber ) delete[] arrayname; } + delete vararr; // Discard result of Tokenize + // cout << line << endl; } diff --git a/src/THcShower.cxx b/src/THcShower.cxx index 046f93e..9b32a64 100644 --- a/src/THcShower.cxx +++ b/src/THcShower.cxx @@ -99,6 +99,7 @@ void THcShower::Setup(const char* name, const char* description) cout << "Created Shower Plane " << fLayerNames[i] << ", " << desc << endl; } + delete [] desc; cout << "THcShower::Setup Return " << GetName() << endl; } -- GitLab