]> git.mxchange.org Git - flightgear.git/commitdiff
Emergency memory leak fix. ***Hopefully*** these fixes will get applied
authorcurt <curt>
Sun, 14 Oct 2001 16:13:00 +0000 (16:13 +0000)
committercurt <curt>
Sun, 14 Oct 2001 16:13:00 +0000 (16:13 +0000)
to JSBSim so they can become permanent.

src/FDM/JSBSim/FGColumnVector3.cpp
src/FDM/JSBSim/FGColumnVector3.h
src/FDM/JSBSim/FGColumnVector4.cpp
src/FDM/JSBSim/FGColumnVector4.h
src/FDM/JSBSim/FGMatrix33.cpp
src/FDM/JSBSim/FGMatrix33.h

index 45fe14c71440768433d7442803f53da465dab51f..4f4f54d315b77bf7f6ba00ef91cf760d01ea2e15 100644 (file)
@@ -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];
index cae83b6f0f882faf04a916e56656e2a9a1db1267..613dde3c5d40e00cf8d4278801b53845cbb29215 100644 (file)
@@ -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);
 };
index 5a0e73868a98a3ca77c068659ecd9c560cde2103..24883abde389d4def7a3f9c51ec2c423b07ba211 100644 (file)
@@ -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];
index a90c021c287f03235012d9769f080c6df1752b1e..5275f0509e58b59edc514bf6fe59b2baa6897af6 100644 (file)
@@ -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);
 };
index 0c69dd7a8ca50843de69a8ee63c4715c58db64bd..10e2e5e7f072610c2eb4edd110dbb60e045a3d5a 100644 (file)
@@ -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];
index be38a1b2805858f2a4ac6feeba89910bc0495ea5..aa86e585c89a2f223153340655fa42b77516d8e9 100644 (file)
@@ -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;