Skip to content

Commit 1d20621

Browse files
committed
Fix memory leak in TF1 constructor NSUM(...) parsing
Created list of functions and list of parameters names was not deleted properly.
1 parent 61a102d commit 1d20621

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

hist/hist/src/TF1.cxx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -618,23 +618,23 @@ TF1::TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, EA
618618
// Go char-by-char to split terms and define the relevant functions
619619
int parenCount = 0;
620620
int termStart = 0;
621-
TObjArray *newFuncs = new TObjArray();
622-
newFuncs->SetOwner(kTRUE);
623-
TObjArray *coeffNames = new TObjArray();
624-
coeffNames->SetOwner(kTRUE);
625-
TString fullFormula("");
621+
TObjArray newFuncs;
622+
newFuncs.SetOwner(kTRUE);
623+
TObjArray coeffNames;
624+
coeffNames.SetOwner(kTRUE);
625+
TString fullFormula;
626626
for (int i = 0; i < formDense.Length(); ++i) {
627627
if (formDense[i] == '(')
628628
parenCount++;
629629
else if (formDense[i] == ')')
630630
parenCount--;
631631
else if (formDense[i] == delimiter && parenCount == 0) {
632632
// term goes from termStart to i
633-
DefineNSUMTerm(newFuncs, coeffNames, fullFormula, formDense, termStart, i, xmin, xmax);
633+
DefineNSUMTerm(&newFuncs, &coeffNames, fullFormula, formDense, termStart, i, xmin, xmax);
634634
termStart = i + 1;
635635
}
636636
}
637-
DefineNSUMTerm(newFuncs, coeffNames, fullFormula, formDense, termStart, formDense.Length(), xmin, xmax);
637+
DefineNSUMTerm(&newFuncs, &coeffNames, fullFormula, formDense, termStart, formDense.Length(), xmin, xmax);
638638

639639
TF1NormSum *normSum = new TF1NormSum(fullFormula, xmin, xmax);
640640

@@ -651,9 +651,8 @@ TF1::TF1(const char *name, const char *formula, Double_t xmin, Double_t xmax, EA
651651

652652
// Parameter names
653653
for (int i = 0; i < fNpar; i++) {
654-
if (coeffNames->At(i)) {
655-
TString coeffName = ((TObjString *)coeffNames->At(i))->GetString();
656-
this->SetParName(i, coeffName.Data());
654+
if (coeffNames.At(i)) {
655+
this->SetParName(i, coeffNames.At(i)->GetName());
657656
} else {
658657
this->SetParName(i, normSum->GetParName(i));
659658
}

0 commit comments

Comments
 (0)