Skip to content

Commit 17a49d1

Browse files
authored
[hist] avoid memleak when SetHistogram, mention transferred ownership (root-project#20254)
[hist] avoid memleak when SetHistogram, mention transferred ownership Fixes root-project#20252
1 parent 9c3ebcc commit 17a49d1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hist/hist/inc/TGraph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ class TGraph : public TNamed, public TAttLine, public TAttFill, public TAttMarke
182182
virtual void Scale(Double_t c1=1., Option_t *option="y"); // *MENU*
183183
virtual void SetEditable(Bool_t editable=kTRUE); // *TOGGLE* *GETTER=GetEditable
184184
virtual void SetHighlight(Bool_t set = kTRUE); // *TOGGLE* *GETTER=IsHighlight
185-
virtual void SetHistogram(TH1F *h) {fHistogram = h;}
185+
virtual void SetHistogram(TH1F *h);
186186
virtual void SetMaximum(Double_t maximum=-1111); // *MENU*
187187
virtual void SetMinimum(Double_t minimum=-1111); // *MENU*
188188
virtual void Set(Int_t n);
189-
virtual void SetOption(Option_t *option = " ") { fOption = option; }
189+
virtual void SetOption(Option_t *option = " ") { fOption = option; }
190190
virtual void SetPoint(Int_t i, Double_t x, Double_t y);
191191
virtual void SetPointX(Int_t i, Double_t x);
192192
virtual void SetPointY(Int_t i, Double_t y);

hist/hist/src/TGraph.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,13 @@ void TGraph::SetHighlight(Bool_t set)
22662266
painter->SetHighlight(this);
22672267
}
22682268

2269+
/// Set the histogram underlying the TGraph. This transfers the ownership of h to the TGraph. The preexisting fHistogram will be deleted.
2270+
void TGraph::SetHistogram(TH1F *h)
2271+
{
2272+
delete fHistogram;
2273+
fHistogram = h;
2274+
}
2275+
22692276
////////////////////////////////////////////////////////////////////////////////
22702277
/// Set the maximum of the graph.
22712278

0 commit comments

Comments
 (0)