Skip to content

Commit 8bd0f6d

Browse files
guitargeekmaxgalli
authored andcommitted
Fix memory leak of rebinned histograms in ShapeTools
Mark the TList that holds the rebinned histograms as the owner of the contained objects, so that they get properly deleted after PyROOT reliquishes the ownership during `TList::Add()`. This was detected by the strict memory policy in ROOT master (root-project/root#13593), where this ownership problem manifested as a segfault from dangling references.
1 parent 6a5a27e commit 8bd0f6d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

python/ShapeTools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ def getPdf(self, channel, process, _cache=None):
946946
if self.options.useHistPdf != "always":
947947
if nominalPdf.InheritsFrom("TH1"):
948948
rebins = ROOT.TList()
949+
rebins.SetOwner(True) # The list takes ownership of the rebinned histograms
949950
maxbins = 0
950951
for i in range(pdfs.GetSize()):
951952
rebinned = self.rebinH1(pdfs.At(i))

0 commit comments

Comments
 (0)