Skip to content

Commit

Permalink
[hist] fix potential memleaks
Browse files Browse the repository at this point in the history
before allocating new memory, make sure we delete potentially existing one previously
  • Loading branch information
ferdymercury authored Oct 28, 2024
1 parent fb76b56 commit 424f787
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hist/hist/src/TH2Poly.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ void TH2Poly::Copy(TObject &newobj) const
newth2p.fStepX = fStepX;
newth2p.fStepY = fStepY;

// deallocate previous arrays, if existing
delete[] newth2p.fCells;
delete[] newth2p.fIsEmpty;
delete[] newth2p.fCompletelyInside;
// allocate arrays
newth2p.fCells = new TList [fNCells];
newth2p.fIsEmpty = new Bool_t [fNCells]; // Empty partition
Expand All @@ -232,6 +236,7 @@ void TH2Poly::Copy(TObject &newobj) const
newth2p.fCompletelyInside[i] = fCompletelyInside[i];
}
// need to use Clone to copy the contained bin list
delete newth2p.fBins; // in case there was something before there
if (!fBins) {
newth2p.fBins = nullptr;
}
Expand Down

0 comments on commit 424f787

Please sign in to comment.