title: munmap_chunk(): invalid pointer in C++ program
body: <p>I get an error "munmap_chunk(): invalid pointer", I don't know why. Problem appears when I use <code>MultipliedByMatrix</code> method. It can't properly delete the matrix that was created in this method.</p>
  
  <pre><code>#include "matrix.h"
  
  Matrix::Matrix(int matr_size) {
      size = matr_size;
      Matr = new int *[size];
      for(int i = 0; i &lt; size; i++)
          Matr[i] = new int[size];
  
      for(int i = 0 ; i &lt; size; i++)
          for(int j = 0; j &lt; size; j++)
              Matr[i][j] = rand() % 100;
      std::cout &lt;&lt; "New matrix is created" &lt;&lt; std::endl;
  }
  
  Matrix::~Matrix() {
      for(int i = 0; i &lt; size; i++)
          delete[] Matr[i];
      delete[] Matr;
      Matr = NULL;
      std::cout &lt;&lt; "Matrix is deleted" &lt;&lt; std::endl;
  }
  
  Matrix Matrix::MultipliedByMatrix(Matrix OtherMatr) {
      Matrix new_matr = Matrix(this-&gt;GetSize());
      int new_value;
  
      for(int i = 0 ; i &lt; size; i++)
          for(int j = 0; j &lt; size; j++) {
              new_value = 0;
              new_value += Matr[j][i] * OtherMatr.GetValue(i, j);
              new_matr.SetValue(i, j, new_value);
          }
      return new_matr;
  }
  
  int Matrix::GetSize() {
      return size;
  }
  
  int Matrix::GetValue(int i, int j) {
      return Matr[i][j];
  }
  
  void Matrix::SetValue(int i, int j, int value) {
      Matr[i][j] = value;
  }
  </code></pre>