1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0022932: Memory leak in math_FunctionRoots.cxx line 254

This commit is contained in:
Pawel, DBV 2012-02-17 08:14:03 +00:00 committed by bugmaster
parent f391e9f2c5
commit 232a30863d

View File

@ -9,6 +9,7 @@
#include <math_DirectPolynomialRoots.hxx> #include <math_DirectPolynomialRoots.hxx>
#include <math_FunctionRoots.ixx> #include <math_FunctionRoots.ixx>
#include <math_FunctionWithDerivative.hxx> #include <math_FunctionWithDerivative.hxx>
#include <TColStd_Array1OfReal.hxx>
//#ifdef WNT //#ifdef WNT
#include <stdio.h> #include <stdio.h>
//#endif //#endif
@ -236,14 +237,14 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
Standard_Real X=X0; Standard_Real X=X0;
Standard_Boolean Ok; Standard_Boolean Ok;
double dx = (XN-X0)/N; double dx = (XN-X0)/N;
double *ptrval = new Standard_Real [N+1]; TColStd_Array1OfReal ptrval(0, N);
Standard_Integer Nvalid = -1; Standard_Integer Nvalid = -1;
Standard_Real aux = 0; Standard_Real aux = 0;
for(i=0; i<=N ; i++,X+=dx) { for(i=0; i<=N ; i++,X+=dx) {
if( X > XN) X=XN; if( X > XN) X=XN;
Ok=F.Value(X,aux); Ok=F.Value(X,aux);
if(Ok) ptrval[++Nvalid] = aux - K; if(Ok) ptrval(++Nvalid) = aux - K;
// ptrval[i]-=K; // ptrval(i)-=K;
} }
//-- Toute la fonction est nulle ? //-- Toute la fonction est nulle ?
@ -255,7 +256,7 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
AllNull=Standard_True; AllNull=Standard_True;
// for(i=0;AllNull && i<=N;i++) { // for(i=0;AllNull && i<=N;i++) {
for(i=0;AllNull && i<=N;i++) { for(i=0;AllNull && i<=N;i++) {
if(ptrval[i]>EpsNull || ptrval[i]<-EpsNull) { if(ptrval(i)>EpsNull || ptrval(i)<-EpsNull) {
AllNull=Standard_False; AllNull=Standard_False;
} }
} }
@ -273,18 +274,18 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
for(i=0,ip1=1,X=X0;i<N; i++,ip1++,X+=dx) { for(i=0,ip1=1,X=X0;i<N; i++,ip1++,X+=dx) {
X2=X+dx; X2=X+dx;
if(X2 > XN) X2 = XN; if(X2 > XN) X2 = XN;
if(ptrval[i]<0.0) { if(ptrval(i)<0.0) {
if(ptrval[ip1]>0.0) { if(ptrval(ip1)>0.0) {
//-- -------------------------------------------------- //-- --------------------------------------------------
//-- changement de signe dans Xi Xi+1 //-- changement de signe dans Xi Xi+1
Solve(F,K,X,ptrval[i],X2,ptrval[ip1],tol,NEpsX,Sol,NbStateSol); Solve(F,K,X,ptrval(i),X2,ptrval(ip1),tol,NEpsX,Sol,NbStateSol);
} }
} }
else { else {
if(ptrval[ip1]<0.0) { if(ptrval(ip1)<0.0) {
//-- -------------------------------------------------- //-- --------------------------------------------------
//-- changement de signe dans Xi Xi+1 //-- changement de signe dans Xi Xi+1
Solve(F,K,X,ptrval[i],X2,ptrval[ip1],tol,NEpsX,Sol,NbStateSol); Solve(F,K,X,ptrval(i),X2,ptrval(ip1),tol,NEpsX,Sol,NbStateSol);
} }
} }
} }
@ -295,7 +296,7 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
//-- Si (F(u0)-K)*(F(u1)-K) <0 on lance une recherche //-- Si (F(u0)-K)*(F(u1)-K) <0 on lance une recherche
//-- Sinon si (F(u0)-K)*(F(u1)-K) !=0 on insere le point X //-- Sinon si (F(u0)-K)*(F(u1)-K) !=0 on insere le point X
for(i=0; i<=N; i++) { for(i=0; i<=N; i++) {
if(ptrval[i]==0) { if(ptrval(i)==0) {
// Standard_Real Val,Deriv; // Standard_Real Val,Deriv;
X=X0+i*dx; X=X0+i*dx;
if (X>XN) X=XN; if (X>XN) X=XN;
@ -321,10 +322,10 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
} }
//-- -------------------------------------------------------------------------------- //-- --------------------------------------------------------------------------------
//-- Il faut traiter differement le cas des points en bout : //-- Il faut traiter differement le cas des points en bout :
if(ptrval[0]<=EpsF && ptrval[0]>=-EpsF) { if(ptrval(0)<=EpsF && ptrval(0)>=-EpsF) {
AppendRoot(Sol,NbStateSol,X0,F,K,NEpsX); AppendRoot(Sol,NbStateSol,X0,F,K,NEpsX);
} }
if(ptrval[N]<=EpsF && ptrval[N]>=-EpsF) { if(ptrval(N)<=EpsF && ptrval(N)>=-EpsF) {
AppendRoot(Sol,NbStateSol,XN,F,K,NEpsX); AppendRoot(Sol,NbStateSol,XN,F,K,NEpsX);
} }
@ -344,8 +345,8 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
for(i=1,xm=X0+dx; i<N; xm+=dx,i++,im1++,ip1++) { for(i=1,xm=X0+dx; i<N; xm+=dx,i++,im1++,ip1++) {
Rediscr = Standard_False; Rediscr = Standard_False;
if (xm > XN) xm=XN; if (xm > XN) xm=XN;
if(ptrval[i]>0.0) { if(ptrval(i)>0.0) {
if((ptrval[im1]>ptrval[i]) && (ptrval[ip1]>ptrval[i])) { if((ptrval(im1)>ptrval(i)) && (ptrval(ip1)>ptrval(i))) {
//-- Peut on traverser l axe Ox //-- Peut on traverser l axe Ox
//-- -------------- Estimation a partir de Xim1 //-- -------------- Estimation a partir de Xim1
xm1=xm-dx; xm1=xm-dx;
@ -371,8 +372,8 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
} }
} }
} }
else if(ptrval[i]<0.0) { else if(ptrval(i)<0.0) {
if((ptrval[im1]<ptrval[i]) && (ptrval[ip1]<ptrval[i])) { if((ptrval(im1)<ptrval(i)) && (ptrval(ip1)<ptrval(i))) {
//-- Peut on traverser l axe Ox //-- Peut on traverser l axe Ox
//-- -------------- Estimation a partir de Xim1 //-- -------------- Estimation a partir de Xim1
xm1=xm-dx; xm1=xm-dx;
@ -409,8 +410,8 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
Standard_Real R=0.61803399; Standard_Real R=0.61803399;
Standard_Real C=1.0-R; Standard_Real C=1.0-R;
Standard_Real tolCR=NEpsX*10.0; Standard_Real tolCR=NEpsX*10.0;
f0=ptrval[im1]; f0=ptrval(im1);
f3=ptrval[ip1]; f3=ptrval(ip1);
x0=xm-dx; x0=xm-dx;
x3=xm+dx; x3=xm+dx;
if(x0 < X0) x0=X0; if(x0 < X0) x0=X0;
@ -473,8 +474,6 @@ math_FunctionRoots::math_FunctionRoots(math_FunctionWithDerivative& F,
} //-- for } //-- for
} }
delete [] ptrval;
#if NEWSEQ #if NEWSEQ
if(methode==3) { if(methode==3) {
StaticSol.Clear(); StaticSol.Clear();