From 2335326a6b9612489848b5f9f0c0f616b30dcb78 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Wed, 15 Nov 2023 20:49:34 -0500 Subject: [PATCH] Revert changes to idPolynomial, add ~idPolynomial() destructor to fix leak properly --- neo/idlib/math/Polynomial.cpp | 7 ------- neo/idlib/math/Polynomial.h | 8 ++++++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/neo/idlib/math/Polynomial.cpp b/neo/idlib/math/Polynomial.cpp index 62c93672..fadba6fd 100644 --- a/neo/idlib/math/Polynomial.cpp +++ b/neo/idlib/math/Polynomial.cpp @@ -231,7 +231,6 @@ void idPolynomial::Test() value = p.GetValue( roots[i] ); assert( idMath::Fabs( value ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( -5.0f, 4.0f, 3.0f ); num = p.GetRoots( roots ); @@ -240,7 +239,6 @@ void idPolynomial::Test() value = p.GetValue( roots[i] ); assert( idMath::Fabs( value ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( 1.0f, 4.0f, 3.0f, -2.0f ); num = p.GetRoots( roots ); @@ -249,7 +247,6 @@ void idPolynomial::Test() value = p.GetValue( roots[i] ); assert( idMath::Fabs( value ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( 5.0f, 4.0f, 3.0f, -2.0f ); num = p.GetRoots( roots ); @@ -258,7 +255,6 @@ void idPolynomial::Test() value = p.GetValue( roots[i] ); assert( idMath::Fabs( value ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( -5.0f, 4.0f, 3.0f, 2.0f, 1.0f ); num = p.GetRoots( roots ); @@ -267,7 +263,6 @@ void idPolynomial::Test() value = p.GetValue( roots[i] ); assert( idMath::Fabs( value ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( 1.0f, 4.0f, 3.0f, -2.0f ); num = p.GetRoots( complexRoots ); @@ -276,7 +271,6 @@ void idPolynomial::Test() complexValue = p.GetValue( complexRoots[i] ); assert( idMath::Fabs( complexValue.r ) < 1e-4f && idMath::Fabs( complexValue.i ) < 1e-4f ); } - Mem_Free16( p.coefficient ); p = idPolynomial( 5.0f, 4.0f, 3.0f, -2.0f ); num = p.GetRoots( complexRoots ); @@ -285,5 +279,4 @@ void idPolynomial::Test() complexValue = p.GetValue( complexRoots[i] ); assert( idMath::Fabs( complexValue.r ) < 1e-4f && idMath::Fabs( complexValue.i ) < 1e-4f ); } - Mem_Free16( p.coefficient ); } diff --git a/neo/idlib/math/Polynomial.h b/neo/idlib/math/Polynomial.h index 3c2ab17d..dc917514 100644 --- a/neo/idlib/math/Polynomial.h +++ b/neo/idlib/math/Polynomial.h @@ -48,6 +48,12 @@ public: explicit idPolynomial( float a, float b, float c, float d ); explicit idPolynomial( float a, float b, float c, float d, float e ); + // SRS - Added destructor, otherwise idPolynomial() will leak memory + ~idPolynomial() + { + Mem_Free16( coefficient ); + }; + float operator[]( int index ) const; float& operator[]( int index ); @@ -190,8 +196,6 @@ ID_INLINE idPolynomial idPolynomial::operator-() const ID_INLINE idPolynomial& idPolynomial::operator=( const idPolynomial& p ) { - allocated = p.allocated; - coefficient = p.coefficient; Resize( p.degree, false ); for( int i = 0; i <= degree; i++ ) {