Commit eb0f160d authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Cleaned up dynamic memory in CubeCalculator, CubeIoHandler, and Cube's unitTest. Fixes #2082.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6044 41f8697f-d340-4b68-9986-7bafba869bb8
parent 348acf88
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -146,6 +146,7 @@ namespace Isis {
   *                           as the buffer shape to ensure virtual bands accessed correctly.
   *                           Added cases to test creating bsq and large bsq cubes.
   *                           References #1689.
   *   @history 2015-01-30 Ian Humphrey - Deallocated copied cubes in unittest. References #2082.
   */
  class Cube {
    public:
+2 −1
Original line number Diff line number Diff line
@@ -230,7 +230,8 @@ namespace Isis {
    delete m_lastProcessByLineChunks;
    m_lastProcessByLineChunks = NULL;
    
    m_dataFile = NULL;
    delete m_writeThreadMutex;
    m_writeThreadMutex = NULL;
  }


+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,8 @@ namespace Isis {
   *                            repeating virtual bands. Fixes #1927.
   *   @history 2014-09-30 Ian Humphrey - Modified read method to correctly access virtual bands
   *                           when cube dimensions and buffer shape are same size. Fixes #1689.
   *   @history 2015-01-30 Ian Humphrey - Modified destructor to free m_writThreadMutex to 
   *                           prevent memory leaks upon destruction. Fixes #2082.
   *
   */
  class CubeIoHandler {
+5 −0
Original line number Diff line number Diff line
@@ -930,6 +930,11 @@ int main(int argc, char *argv[]) {
    catch (IException &e) {
      e.print();
    }
    // need to deallocate our copied cube
    copiedCube->close();
    delete copiedCube;
    copiedCube = NULL;
    
  }

  remove("IsisCube_00.cub");
+37 −5
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ namespace Isis {
  CubeCalculator::CubeCalculator() {
    m_calculations    = NULL;
    m_methods         = NULL;
    m_data            = NULL;
    // m_data was never used anywhere
//     m_data            = NULL;
    m_dataDefinitions = NULL;
    m_cubeStats       = NULL;
    m_cubeCameras     = NULL;
@@ -45,7 +46,8 @@ namespace Isis {

    m_calculations    = new QVector<Calculations>();
    m_methods         = new QVector<void (Calculator:: *)(void)>();
    m_data            = new QVector<QVector<double> >();
    // m_data was never used anywhere
//     m_data            = new QVector<QVector<double> >();
    m_dataDefinitions = new QVector<DataValue>();
    m_cubeStats       = new QVector<Statistics *>();
    m_cubeCameras     = new QVector<Camera *>();
@@ -54,6 +56,25 @@ namespace Isis {
    m_outputSamples = 0;
  }

  
  //! Destroys the CubeCalculator object
  CubeCalculator::~CubeCalculator() {
    delete m_calculations;
    delete m_methods;
    delete m_dataDefinitions;
    delete m_cubeStats;
    delete m_cubeCameras;
    delete m_cameraBuffers;
    
    m_calculations = NULL;
    m_methods = NULL;
    m_dataDefinitions = NULL;
    m_cubeStats = NULL;
    m_cubeCameras = NULL;
    m_cameraBuffers = NULL;
  }
  
  
  void CubeCalculator::Clear() {
    Calculator::Clear();

@@ -65,15 +86,20 @@ namespace Isis {
      m_methods->clear();
    }

    if (m_data) {
      m_data->clear();
    }
//     if (m_data) {
//       m_data->clear();
//     }

    if (m_dataDefinitions) {
      m_dataDefinitions->clear();
    }

    // m_cubeStats contains pointers to dynamic memory - need to free
    if (m_cubeStats) {
      for (int i = 0; i < m_cubeStats->size(); i++) {
        delete (*m_cubeStats)[i];
        (*m_cubeStats)[i] = NULL;
      }
      m_cubeStats->clear();
    }

@@ -81,11 +107,17 @@ namespace Isis {
      m_cubeCameras->clear();
    }

    // m_cameraBuffers contains pointers to dynamic memory - need to free
    if (m_cameraBuffers) {
      for (int i = 0; i < m_cameraBuffers->size(); i++) {
        delete (*m_cameraBuffers)[i];
        (*m_cameraBuffers)[i] = NULL;
      }
      m_cameraBuffers->clear();
    }
  }

  
  /**
   * This method will execute the calculations built up when PrepareCalculations was called.
   *
Loading