title: C Error: free(): invalid next size (fast):, different behaviour of C program on OSX, Linux
body: <p>This question has been asked several times, but since I think my situation is I think more specific:</p>
  
  <p>I have a C program, which works perfectly on my OSX system (too huge to copy). I already tested it with Valgrind, and I am not missing any frees /mallocs /or writes, all problems are solved 100%.</p>
  
  <p>When I now run the program over ssh on an external sever, when I run with not that many data (see code below, my_length &lt; 1000), it works without any problem. But with a larger dataset, using the Linux terminal I get this error:</p>
  
  <pre><code> *** Error in `./a.out': free(): invalid next size (fast): 0x00000000016b9ed0 ***
   ======= Backtrace: =========
   /lib64/libc.so.6[0x3e50475cff]
   /lib64/libc.so.6[0x3e5047cff8]
   ./a.out[0x41083c]
   ./a.out[0x402374]
   /lib64/libc.so.6(__libc_start_main+0xf5)[0x3e50421d65]
   ./a.out[0x400e79]
   ======= Memory map: ========
    00400000-00418000 r-xp 00000000 00:4d 89038   
  </code></pre>
  
  <p>[...]</p>
  
  <p>and when I run it on Solaris it complains :</p>
  
  <pre><code>malloc failed
  </code></pre>
  
  <p>at a line where I allocate a three dimensional array:</p>
  
  <pre><code> int ***A, ***B, ***C;
   A = malloc(sizeof(int**)*2); B = malloc(sizeof(int**)*2); C = malloc(sizeof(int**)*2);
   int i;
   for (i = 0; i &lt; 2; i++) {
      A[i] = malloc(sizeof(int*)* my_length);
      B[i] = malloc(sizeof(int*)* my_length);
      C[i] = malloc(sizeof(int*)* my_length);
      for (j = 0; j &lt;= my_length2; j++) {
          A[i][j] = malloc(sizeof(int)* my_length2);
          B[i][j] = malloc(sizeof(int)* my_length2);
          C[i][j] = malloc(sizeof(int)* my_length2);&lt;== malloc failed here??
      }   
  }
  </code></pre>
  
  <p>where <code>my_length</code> and <code>my_length2</code> get really really huge!</p>
  
  <p>I am getting desperate! Does someone have any clue what my problem could be?</p>