Skip to content
Snippets Groups Projects
Commit a46ba8d3 authored by Fons Rademakers's avatar Fons Rademakers
Browse files

fix memory leak in case max_value < singularity_tolerance. Found by

Paul Balm.


git-svn-id: http://root.cern.ch/svn/root/trunk@4332 27541ba8-7e3a-0410-8455-c3a389f83636
parent 72a5283a
No related branches found
No related tags found
No related merge requests found
// @(#)root/matrix:$Name: $:$Id: TMatrix.cxx,v 1.13 2002/01/04 08:14:30 brun Exp $ // @(#)root/matrix:$Name: $:$Id: TMatrix.cxx,v 1.14 2002/02/27 08:39:26 brun Exp $
// Author: Fons Rademakers 03/11/97 // Author: Fons Rademakers 03/11/97
/************************************************************************* /*************************************************************************
...@@ -979,7 +979,11 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr) ...@@ -979,7 +979,11 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr)
if (!was_pivoted[k] && (curr_value = TMath::Abs(*cp)) > max_value) if (!was_pivoted[k] && (curr_value = TMath::Abs(*cp)) > max_value)
max_value = curr_value, prow = k, pcol = j; max_value = curr_value, prow = k, pcol = j;
} }
if (max_value < singularity_tolerance) if (max_value < singularity_tolerance) {
// free allocated heap memory before returning
if (symmetric) delete [] diag;
delete [] pivots;
delete [] was_pivoted;
if (determ_ptr) { if (determ_ptr) {
*determ_ptr = 0; *determ_ptr = 0;
return *this; return *this;
...@@ -987,6 +991,7 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr) ...@@ -987,6 +991,7 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr)
Error("Invert(Double_t*)", "matrix turns out to be singular: can't invert"); Error("Invert(Double_t*)", "matrix turns out to be singular: can't invert");
return *this; return *this;
} }
}
pivotp->row = prow; pivotp->row = prow;
pivotp->col = pcol; pivotp->col = pcol;
} }
...@@ -1054,6 +1059,7 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr) ...@@ -1054,6 +1059,7 @@ TMatrix &TMatrix::Invert(Double_t *determ_ptr)
delete [] was_pivoted; delete [] was_pivoted;
delete [] pivots; delete [] pivots;
return *this; return *this;
} }
......
// @(#)root/matrix:$Name: $:$Id: TMatrixD.cxx,v 1.14 2002/01/30 07:00:30 brun Exp $ // @(#)root/matrix:$Name: $:$Id: TMatrixD.cxx,v 1.15 2002/02/27 08:39:27 brun Exp $
// Author: Fons Rademakers 03/11/97 // Author: Fons Rademakers 03/11/97
/************************************************************************* /*************************************************************************
...@@ -981,7 +981,11 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr) ...@@ -981,7 +981,11 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr)
if (!was_pivoted[k] && (curr_value = TMath::Abs(*cp)) > max_value) if (!was_pivoted[k] && (curr_value = TMath::Abs(*cp)) > max_value)
max_value = curr_value, prow = k, pcol = j; max_value = curr_value, prow = k, pcol = j;
} }
if (max_value < singularity_tolerance) if (max_value < singularity_tolerance) {
// free allocated heap memory before returning
if (symmetric) delete [] diag;
delete [] pivots;
delete [] was_pivoted;
if (determ_ptr) { if (determ_ptr) {
*determ_ptr = 0; *determ_ptr = 0;
return *this; return *this;
...@@ -989,6 +993,7 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr) ...@@ -989,6 +993,7 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr)
Error("Invert(Double_t*)", "matrix turns out to be singular: can't invert"); Error("Invert(Double_t*)", "matrix turns out to be singular: can't invert");
return *this; return *this;
} }
}
pivotp->row = prow; pivotp->row = prow;
pivotp->col = pcol; pivotp->col = pcol;
} }
...@@ -1056,7 +1061,7 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr) ...@@ -1056,7 +1061,7 @@ TMatrixD &TMatrixD::Invert(Double_t *determ_ptr)
delete [] was_pivoted; delete [] was_pivoted;
delete [] pivots; delete [] pivots;
//delete [] diag;
return *this; return *this;
} }
...@@ -1308,7 +1313,7 @@ TVectorD &e) ...@@ -1308,7 +1313,7 @@ TVectorD &e)
a.Zero(); a.Zero();
d.Zero(); d.Zero();
e.Zero(); e.Zero();
return; return;
} }
Double_t *pa = a.fElements; Double_t *pa = a.fElements;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment