title: c++ valgrind double pointer delete for memory leak prevention
body: <p>After reading:
  <a href="https://stackoverflow.com/questions/2814188/c-array-of-pointers-delete-or-delete">C++ Array of pointers: delete or delete []?</a>
  (reply by shai vashid)
  and
  <a href="http://www.cplusplus.com/forum/beginner/6651/" rel="nofollow noreferrer">http://www.cplusplus.com/forum/beginner/6651/</a></p>
  
  <p>I implemented following:</p>
  
  <p>Kernel.h</p>
  
  <pre><code>unsigned int **ConfigMeM;
  //.....
  ~Kernel(){ //destructor
      for (unsigned int i=0; i&lt;MeMSize; i++)
          delete [] MeM[i]; //Valgrind:- Invalid read of size 4
                                         - Invalid free() / delete / delete[] / realloc()
      delete [] MeM; //Valgrind: Invalid free() / delete / delete[] / realloc()
  
      for (unsigned int i=0; i&lt;_item_tot; i++)
          delete [] ConfigMeM[i]; //Valgrind: Same comments as above
      delete [] ConfigMeM; //Valgrind: same as above
  };
  </code></pre>
  
  <p>Kernel.cpp</p>
  
  <pre><code>//.......
  MeM = new unsigned int*[MeMSize];
  for (unsigned int i=0; i&lt;MeMSize; i++){
      MeM[i] = new unsigned int[11]; //Valgrind: 14,608 bytes in 332 blocks are definitely lost in loss record 2,021 of 2,036
  }
  for (unsigned int i=0; i&lt;MeMSize; i++){
      for (int j=0; j&lt;10; j++){
          MeM[i][j] = 0;
      }
  }
   //.....
   ConfigMeM = new unsigned int*[_item_tot];
  for (unsigned int i=0; i&lt;_item_tot; i++){
      ConfigMeM[i] = new unsigned int[3]; //Valgrind: 1,200 bytes in 100 blocks are definitely lost in loss record 1,131 of 2,036 
  }
  for (unsigned int i=0; i&lt;_item_tot; i++){
      for (int j=0; j&lt;3; j++){
          ConfigMeM[i][j] = 0;
      }
  }
    //.....
  </code></pre>
  
  <p>I am not sure what I am doing wrong.</p>
  
  <p>Any suggestions please?</p>
  
  <p>Thank you.</p>