Skip to content

Commit 8bb3f2f

Browse files
authored
[PWGCF] Fix memory leaks and other issues in GFWCore (#18216)
1 parent 7512c03 commit 8bb3f2f

7 files changed

Lines changed: 397 additions & 206 deletions

File tree

‎PWGCF/GenericFramework/Core/FlowContainer.cxx‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ TProfile* FlowContainer::GetCorrXXVsMulti(const char* order, int l_pti)
415415
}
416416
delete rethist;
417417
}
418+
if (!retSubset) {
419+
LOGF(error, "Correlation profile is null");
420+
return nullptr;
421+
}
418422
if (fMultiRebin > 0) {
419423
TString temp_name(retSubset->GetName());
420424
TProfile* tempprof = dynamic_cast<TProfile*>(retSubset->Clone("tempProfile"));
@@ -525,9 +529,9 @@ TH1D* FlowContainer::GetCN2VsX(int n, bool onPt, double arg1, double arg2)
525529
corrN2 = GetHistCorrXXVsMulti(Form("%i2", n), static_cast<int>(arg1));
526530
corrN2->SetName(Form("Corr_%s", corrN2->GetName()));
527531
TH1D* rethist = GetCN2(corrN2);
528-
TString* nam = new TString(corrN2->GetName());
532+
const TString nam(corrN2->GetName());
529533
delete corrN2;
530-
rethist->SetName(nam->Data());
534+
rethist->SetName(nam.Data());
531535
if (onPt) {
532536
int bins = fProf->GetXaxis()->FindBin(arg1);
533537
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -543,10 +547,10 @@ TH1D* FlowContainer::GetCN2VsX(int n, bool onPt, double arg1, double arg2)
543547
TH1D* FlowContainer::GetVN2VsX(int n, bool onPt, double arg1, double arg2)
544548
{
545549
TH1D* corrh = GetCN2VsX(n, onPt, arg1, arg2);
546-
TString* nam = new TString(corrh->GetName());
550+
const TString nam(corrh->GetName());
547551
TH1D* rethist = GetVN2(corrh);
548552
delete corrh;
549-
rethist->SetName(nam->Data());
553+
rethist->SetName(nam.Data());
550554
if (onPt) {
551555
int bins = fProf->GetXaxis()->FindBin(arg1);
552556
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -556,7 +560,6 @@ TH1D* FlowContainer::GetVN2VsX(int n, bool onPt, double arg1, double arg2)
556560
} else {
557561
rethist->SetTitle(Form(";#it{N}_{tr};v_{%i}{2}", n));
558562
}
559-
delete nam;
560563
return rethist;
561564
}
562565

@@ -706,10 +709,10 @@ TH1D* FlowContainer::GetCN4VsX(int n, bool onPt, double arg1, double arg2)
706709
corrN4->SetName(Form("Corr_%s", corrN4->GetName()));
707710
}
708711
TH1D* rethist = GetCN4(corrN4, corrN2);
709-
TString* nam = new TString(corrN4->GetName());
712+
const TString nam(corrN4->GetName());
710713
delete corrN2;
711714
delete corrN4;
712-
rethist->SetName(nam->Data());
715+
rethist->SetName(nam.Data());
713716
if (onPt) {
714717
int bins = fProf->GetXaxis()->FindBin(arg1);
715718
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -780,9 +783,9 @@ TH1D* FlowContainer::GetVN4VsX(int n, bool onPt, double arg1, double arg2)
780783
{
781784
TH1D* temph = GetCN4VsX(n, onPt, arg1, arg2);
782785
TH1D* rethist = GetVN4(temph);
783-
TString* nam = new TString(temph->GetName());
786+
const TString nam(temph->GetName());
784787
delete temph;
785-
rethist->SetName(nam->Data());
788+
rethist->SetName(nam.Data());
786789
if (onPt) {
787790
int bins = fProf->GetXaxis()->FindBin(arg1);
788791
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -812,9 +815,9 @@ TH1D* FlowContainer::GetCN6VsX(int n, bool onPt, double arg1, double arg2)
812815
TH1D* rethist = GetCN6(corrN6, corrN4, corrN2);
813816
delete corrN2;
814817
delete corrN4;
815-
TString* nam = new TString(corrN6->GetName());
818+
const TString nam(corrN6->GetName());
816819
delete corrN6;
817-
rethist->SetName(nam->Data());
820+
rethist->SetName(nam.Data());
818821
if (onPt) {
819822
int bins = fProf->GetXaxis()->FindBin(arg1);
820823
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -830,9 +833,9 @@ TH1D* FlowContainer::GetVN6VsX(int n, bool onPt, double arg1, double arg2)
830833
{
831834
TH1D* temph = GetCN6VsX(n, onPt, arg1, arg2);
832835
TH1D* rethist = GetVN6(temph);
833-
TString* nam = new TString(temph->GetName());
836+
const TString nam(temph->GetName());
834837
delete temph;
835-
rethist->SetName(nam->Data());
838+
rethist->SetName(nam.Data());
836839
if (onPt) {
837840
int bins = fProf->GetXaxis()->FindBin(arg1);
838841
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -866,9 +869,9 @@ TH1D* FlowContainer::GetCN8VsX(int n, bool onPt, double arg1, double arg2)
866869
delete corrN2;
867870
delete corrN4;
868871
delete corrN6;
869-
TString* nam = new TString(corrN8->GetName());
872+
const TString nam(corrN8->GetName());
870873
delete corrN8;
871-
rethist->SetName(nam->Data());
874+
rethist->SetName(nam.Data());
872875
if (onPt) {
873876
int bins = fProf->GetXaxis()->FindBin(arg1);
874877
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -884,9 +887,9 @@ TH1D* FlowContainer::GetVN8VsX(int n, bool onPt, double arg1, double arg2)
884887
{
885888
TH1D* temph = GetCN8VsX(n, onPt, arg1, arg2);
886889
TH1D* rethist = GetVN8(temph);
887-
TString* nam = new TString(temph->GetName());
890+
const TString nam(temph->GetName());
888891
delete temph;
889-
rethist->SetName(nam->Data());
892+
rethist->SetName(nam.Data());
890893
if (onPt) {
891894
int bins = fProf->GetXaxis()->FindBin(arg1);
892895
int bins2 = fProf->GetXaxis()->FindBin(arg2);
@@ -928,7 +931,7 @@ TProfile* FlowContainer::GetRefFlowProfile(const char* order, double m1, double
928931
if (nStopBin < nStartBin)
929932
nStopBin = fProf->GetXaxis()->GetNbins();
930933
int nBins = nStopBin - nStartBin + 1;
931-
double* l_bins = new double[nBins + 1];
934+
std::vector<double> l_bins(nBins + 1);
932935
for (int i = 0; i <= nBins; i++)
933936
l_bins[i] = i;
934937
TProfile* retpf = 0;
@@ -939,7 +942,7 @@ TProfile* FlowContainer::GetRefFlowProfile(const char* order, double m1, double
939942
while (fIDName.Tokenize(l_name, l_pos)) {
940943
l_name.Append(order);
941944
int ybin = fProf->GetYaxis()->FindBin(l_name.Data());
942-
TProfile* tempprof = rhSubset->GetSubset(kTRUE, "tempprof", ybin, ybin, nBins, l_bins);
945+
TProfile* tempprof = rhSubset->GetSubset(kTRUE, "tempprof", ybin, ybin, nBins, l_bins.data());
943946
if (!retpf)
944947
retpf = dynamic_cast<TProfile*>(tempprof->Clone("RefFlowProf"));
945948
else
@@ -1237,5 +1240,5 @@ double* FlowContainer::GetMultiRebin(int& nbins)
12371240
double* retBins = new double[fMultiRebin + 1];
12381241
for (int i = 0; i <= nbins; i++)
12391242
retBins[i] = fMultiRebinEdges[i];
1240-
return fMultiRebinEdges;
1243+
return retBins;
12411244
}

0 commit comments

Comments
 (0)