From a5ee77406f01d9cde3886a8dc93e284b5a6fa71e Mon Sep 17 00:00:00 2001 From: curt Date: Sun, 14 Oct 2001 16:13:00 +0000 Subject: [PATCH] Emergency memory leak fix. ***Hopefully*** these fixes will get applied to JSBSim so they can become permanent. --- src/FDM/JSBSim/FGColumnVector3.cpp | 6 ---- src/FDM/JSBSim/FGColumnVector3.h | 5 +-- src/FDM/JSBSim/FGColumnVector4.cpp | 6 ---- src/FDM/JSBSim/FGColumnVector4.h | 5 +-- src/FDM/JSBSim/FGMatrix33.cpp | 49 ------------------------------ src/FDM/JSBSim/FGMatrix33.h | 6 ++-- 6 files changed, 9 insertions(+), 68 deletions(-) diff --git a/src/FDM/JSBSim/FGColumnVector3.cpp b/src/FDM/JSBSim/FGColumnVector3.cpp index 45fe14c71..4f4f54d31 100644 --- a/src/FDM/JSBSim/FGColumnVector3.cpp +++ b/src/FDM/JSBSim/FGColumnVector3.cpp @@ -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]; diff --git a/src/FDM/JSBSim/FGColumnVector3.h b/src/FDM/JSBSim/FGColumnVector3.h index cae83b6f0..613dde3c5 100644 --- a/src/FDM/JSBSim/FGColumnVector3.h +++ b/src/FDM/JSBSim/FGColumnVector3.h @@ -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); }; diff --git a/src/FDM/JSBSim/FGColumnVector4.cpp b/src/FDM/JSBSim/FGColumnVector4.cpp index 5a0e73868..24883abde 100644 --- a/src/FDM/JSBSim/FGColumnVector4.cpp +++ b/src/FDM/JSBSim/FGColumnVector4.cpp @@ -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]; diff --git a/src/FDM/JSBSim/FGColumnVector4.h b/src/FDM/JSBSim/FGColumnVector4.h index a90c021c2..5275f0509 100644 --- a/src/FDM/JSBSim/FGColumnVector4.h +++ b/src/FDM/JSBSim/FGColumnVector4.h @@ -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); }; diff --git a/src/FDM/JSBSim/FGMatrix33.cpp b/src/FDM/JSBSim/FGMatrix33.cpp index 0c69dd7a8..10e2e5e7f 100644 --- a/src/FDM/JSBSim/FGMatrix33.cpp +++ b/src/FDM/JSBSim/FGMatrix33.cpp @@ -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]; diff --git a/src/FDM/JSBSim/FGMatrix33.h b/src/FDM/JSBSim/FGMatrix33.h index be38a1b28..aa86e585c 100644 --- a/src/FDM/JSBSim/FGMatrix33.h +++ b/src/FDM/JSBSim/FGMatrix33.h @@ -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; -- 2.39.5