Revert changes to idPolynomial, add ~idPolynomial() destructor to fix leak properly

This commit is contained in:
Stephen Saunders 2023-11-15 20:49:34 -05:00 committed by Robert Beckebans
parent fe411ba3b5
commit 2335326a6b
2 changed files with 6 additions and 9 deletions

View file

@ -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 );
}

View file

@ -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++ )
{