title: Why does this program crash when freeing?
body: <p>I'm trying to understand why does this program crash, when I use this line and trying to free the pointer:</p>
  <pre><code> t_mat *C=malloc(sizeof(t_mat));
  </code></pre>
  <p>But works well with the following line (no memory leaks, no crashing, the value 53 is the minimum I found by trial and error):</p>
  <pre><code> t_mat *C=malloc(sizeof(t_mat)+53);
  </code></pre>
  <p>Program: (the while(1) loop is for memory leak testing, doesn't affect the crashing)</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt; 
  typedef int t_mat[3][3];
  t_mat* matice(t_mat A, t_mat B, char op)
  {
      t_mat *C=malloc(sizeof(t_mat)+53);
      switch(op)
      {
      case '+':
          for(int i=0; i&lt;3; i++)
              for(int j=0; j&lt;3; j++)
                  *C[i][j]=A[i][j]+B[i][j];
          return *C;
          break;
      case '-':
          for(int i=0; i&lt;3; i++)
              for(int j=0; j&lt;3; j++)
                  *C[i][j]=A[i][j]-B[i][j];
          return *C;
          break;
      default:
          free(C);
          printf(&quot;Chyba\n&quot;);
          return NULL;
          break;
      }
  }
  int main()
  {
      char op;
      scanf(&quot;%c&quot;,&amp;op);
      getchar();
      t_mat A = {0,1,2,3,4,5,6,7,8},B= {0,1,2,3,4,5,6,7,8},*C;
      while(1)
      {
          C=matice(A, B, op);
          for(int i=0; i&lt;3; i++)
              for(int j=0; j&lt;3; j++)
                  printf(&quot;%d\n&quot;,*C[i][j]);
          free(C);
          C=NULL;
      }
      return 0;
  }
  </code></pre>
  <p>Am I missing something here ?</p>