title: Deallocating rectangular 2d arrays gives error depending on dimensions
body: <p>I create a dynamically allocated 2d array and when I try to delete it, I get an error depending on the dimensions of the array.</p>
  
  <p>If there are more rows than columns, there is no issue:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main(){
  
      int num_rows = 8;
      int num_cols = 6;
  
      char **charBoard = new char*[num_rows+1];
      for(int i = 0; i&lt;=num_cols; i++){
          charBoard[i] = new char[num_cols+1];
      }
  
      for (int i = 0; i &lt;=num_rows; i++){
          delete[] charBoard[i];
  
      }   
      //free the main array
      delete[] charBoard;
  
  return 0;   
  }
  </code></pre>
  
  <p>If there are more columns than rows, I get an error:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  int main(){
  
      int num_rows = 4;
      int num_cols = 6;
  
      char **charBoard = new char*[num_rows+1];
      for(int i = 0; i&lt;=num_cols; i++){
          charBoard[i] = new char[num_cols+1];
      }
  
      for (int i = 0; i &lt;=num_rows; i++){
          delete[] charBoard[i];
  
      }   
      //free the main array
      delete[] charBoard;
  
  return 0;   
  }
  </code></pre>
  
  <p>Then I get this error:
  Aborted (core dumped)</p>
  
  <p>I have no idea why.  Am I improperly deleting something?</p>