Emergency memory leak fix. ***Hopefully*** these fixes will get applied
to JSBSim so they can become permanent.
This commit is contained in:
parent
2fbab0d702
commit
a5ee77406f
6 changed files with 9 additions and 68 deletions
|
@ -31,7 +31,6 @@ CLASS IMPLEMENTATION
|
|||
|
||||
FGColumnVector3::FGColumnVector3(void)
|
||||
{
|
||||
data = new double[4];
|
||||
rowCtr = 1;
|
||||
//cout << "Allocated: " << data << endl;
|
||||
//if (debug_lvl & 2) cout << "Instantiated: FGColumnVector3" << endl;
|
||||
|
@ -41,7 +40,6 @@ FGColumnVector3::FGColumnVector3(void)
|
|||
|
||||
FGColumnVector3::FGColumnVector3(int m)
|
||||
{
|
||||
data = new double[4];
|
||||
rowCtr = 1;
|
||||
data[1]=0;data[2]=0;data[3]=0;
|
||||
//cout << "Allocated: " << data << endl;
|
||||
|
@ -53,8 +51,6 @@ FGColumnVector3::FGColumnVector3(int m)
|
|||
FGColumnVector3::~FGColumnVector3(void)
|
||||
{
|
||||
//cout << "Freed: " << data << endl;
|
||||
delete[] data;
|
||||
data = NULL;
|
||||
if (debug_lvl & 2) cout << "Destroyed: FGColumnVector3" << endl;
|
||||
}
|
||||
|
||||
|
@ -63,7 +59,6 @@ FGColumnVector3::~FGColumnVector3(void)
|
|||
|
||||
FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
|
||||
{
|
||||
data = new double[4];
|
||||
data[1] = b.data[1];
|
||||
data[2] = b.data[2];
|
||||
data[3] = b.data[3];
|
||||
|
@ -76,7 +71,6 @@ FGColumnVector3::FGColumnVector3(const FGColumnVector3& b)
|
|||
|
||||
FGColumnVector3 FGColumnVector3::operator=(const FGColumnVector3& b)
|
||||
{
|
||||
data = new double[4];
|
||||
data[1] = b.data[1];
|
||||
data[2] = b.data[2];
|
||||
data[3] = b.data[3];
|
||||
|
|
|
@ -108,12 +108,13 @@ public:
|
|||
|
||||
friend ostream& operator<<(ostream& os, const FGColumnVector3& col);
|
||||
|
||||
inline double& operator()(int m) const { return data[m]; }
|
||||
inline double operator()(int m) const { return data[m]; }
|
||||
inline double& operator()(int m) { return data[m]; }
|
||||
|
||||
FGColumnVector3 multElementWise(const FGColumnVector3& V);
|
||||
|
||||
private:
|
||||
double *data;
|
||||
double data[4];
|
||||
int rowCtr;
|
||||
void Debug(void);
|
||||
};
|
||||
|
|
|
@ -29,7 +29,6 @@ CLASS IMPLEMENTATION
|
|||
|
||||
FGColumnVector4::FGColumnVector4(void)
|
||||
{
|
||||
data = new double[5];
|
||||
rowCtr = 1;
|
||||
//cout << "Allocated: " << data << endl;
|
||||
if (debug_lvl & 2) cout << "Instantiated: FGColumnVector4" << endl;
|
||||
|
@ -39,7 +38,6 @@ FGColumnVector4::FGColumnVector4(void)
|
|||
|
||||
FGColumnVector4::FGColumnVector4(int m)
|
||||
{
|
||||
data = new double[5];
|
||||
rowCtr = 1;
|
||||
data[1]=0;data[2]=0;data[3]=0;data[4]=0;
|
||||
//cout << "Allocated: " << data << endl;
|
||||
|
@ -51,8 +49,6 @@ FGColumnVector4::FGColumnVector4(int m)
|
|||
FGColumnVector4::~FGColumnVector4(void)
|
||||
{
|
||||
//cout << "Freed: " << data << endl;
|
||||
delete[] data;
|
||||
data = NULL;
|
||||
if (debug_lvl & 2) cout << "Destroyed: FGColumnVector4" << endl;
|
||||
}
|
||||
|
||||
|
@ -61,7 +57,6 @@ FGColumnVector4::~FGColumnVector4(void)
|
|||
|
||||
FGColumnVector4::FGColumnVector4(const FGColumnVector4& b)
|
||||
{
|
||||
data = new double[5];
|
||||
data[1] = b.data[1];
|
||||
data[2] = b.data[2];
|
||||
data[3] = b.data[3];
|
||||
|
@ -76,7 +71,6 @@ FGColumnVector4::FGColumnVector4(const FGColumnVector4& b)
|
|||
|
||||
FGColumnVector4 FGColumnVector4::operator=(const FGColumnVector4& b)
|
||||
{
|
||||
data = new double[5];
|
||||
data[1] = b.data[1];
|
||||
data[2] = b.data[2];
|
||||
data[3] = b.data[3];
|
||||
|
|
|
@ -92,7 +92,8 @@ public:
|
|||
void operator*=(const double scalar);
|
||||
void operator/=(const double scalar);
|
||||
|
||||
inline double& operator()(int m) const { return data[m]; }
|
||||
inline double operator()(int m) const { return data[m]; }
|
||||
inline double& operator()(int m) { return data[m]; }
|
||||
|
||||
FGColumnVector4& operator<<(const float ff);
|
||||
|
||||
|
@ -110,7 +111,7 @@ public:
|
|||
FGColumnVector4 multElementWise(const FGColumnVector4& V);
|
||||
|
||||
private:
|
||||
double *data;
|
||||
double data[5];
|
||||
int rowCtr;
|
||||
void Debug(void);
|
||||
};
|
||||
|
|
|
@ -28,51 +28,10 @@ static const char *IdHdr = ID_MATRIX33;
|
|||
CLASS IMPLEMENTATION
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
double** FGalloc(void)
|
||||
{
|
||||
double **A;
|
||||
|
||||
A = new double *[4];
|
||||
if (!A) return NULL;
|
||||
|
||||
double *tmp;
|
||||
tmp = new double [16];
|
||||
|
||||
if (!tmp) {
|
||||
delete A;
|
||||
return NULL;
|
||||
}
|
||||
A[0] = tmp;
|
||||
A[1] = tmp + 4;
|
||||
A[2] = tmp + 8;
|
||||
A[3] = tmp + 12;
|
||||
#if 0
|
||||
A[0] = new double [4];
|
||||
if (!A[0]) return NULL;
|
||||
A[1] = new double [4];
|
||||
if (!A[1]) return NULL;
|
||||
A[2] = new double [4];
|
||||
if (!A[2]) return NULL;
|
||||
A[3] = new double [4];
|
||||
if (!A[3]) return NULL;
|
||||
#endif
|
||||
|
||||
return A;
|
||||
}
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
void dealloc(double **A)
|
||||
{
|
||||
delete[] A[0];
|
||||
delete[] A;
|
||||
}
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
FGMatrix33::FGMatrix33(void)
|
||||
{
|
||||
data=FGalloc();
|
||||
InitMatrix();
|
||||
rowCtr = colCtr = 1;
|
||||
|
||||
|
@ -83,7 +42,6 @@ FGMatrix33::FGMatrix33(void)
|
|||
|
||||
FGMatrix33::FGMatrix33(int r, int c)
|
||||
{
|
||||
data=FGalloc();
|
||||
InitMatrix();
|
||||
rowCtr = colCtr = 1;
|
||||
|
||||
|
@ -100,8 +58,6 @@ FGMatrix33::FGMatrix33(const FGMatrix33& M)
|
|||
delim = M.delim;
|
||||
origin = M.origin;
|
||||
|
||||
data=FGalloc();
|
||||
|
||||
data[1][1] = M.data[1][1];
|
||||
data[1][2] = M.data[1][2];
|
||||
data[1][3] = M.data[1][3];
|
||||
|
@ -119,7 +75,6 @@ FGMatrix33::FGMatrix33(const FGMatrix33& M)
|
|||
|
||||
FGMatrix33::~FGMatrix33(void)
|
||||
{
|
||||
dealloc(data);
|
||||
rowCtr = colCtr = 1;
|
||||
|
||||
if (debug_lvl & 2) cout << "Destroyed: FGMatrix33" << endl;
|
||||
|
@ -170,15 +125,11 @@ istream& operator>>(istream& is, FGMatrix33& M)
|
|||
FGMatrix33& FGMatrix33::operator=(const FGMatrix33& M)
|
||||
{
|
||||
if (&M != this) {
|
||||
if (data != NULL) dealloc(data);
|
||||
|
||||
width = M.width;
|
||||
prec = M.prec;
|
||||
delim = M.delim;
|
||||
origin = M.origin;
|
||||
|
||||
data=FGalloc();
|
||||
|
||||
data[1][1] = M.data[1][1];
|
||||
data[1][2] = M.data[1][2];
|
||||
data[1][3] = M.data[1][3];
|
||||
|
|
|
@ -92,7 +92,8 @@ public:
|
|||
~FGMatrix33(void);
|
||||
|
||||
FGMatrix33& operator=(const FGMatrix33& A);
|
||||
inline double& operator()(unsigned int row, unsigned int col) const {return data[row][col];}
|
||||
inline double operator()(unsigned int row, unsigned int col) const {return data[row][col];}
|
||||
inline double& operator()(unsigned int row, unsigned int col) {return data[row][col];}
|
||||
|
||||
FGColumnVector3 operator*(const FGColumnVector3& Col);
|
||||
|
||||
|
@ -121,11 +122,10 @@ public:
|
|||
void operator*=(const double scalar);
|
||||
void operator/=(const double scalar);
|
||||
|
||||
|
||||
void SetOParams(char delim,int width,int prec, int origin=0);
|
||||
|
||||
protected:
|
||||
double **data;
|
||||
double data[4][4];
|
||||
|
||||
private:
|
||||
char delim;
|
||||
|
|
Loading…
Reference in a new issue