title: c realloc(): invalid next size
body: <p>I get this error and searching online hasn't solved it so, here's my code^^:</p>
  <pre><code>void addSoggetto(char* s)
  {
      soggetti_length++;
      if(realloc(soggetti, soggetti_length*sizeof(int))==NULL) 
      {
          printf(&quot;Realloc Failed&quot;);
          return;
      }
  </code></pre>
  <p>Basically I have an array of pointers (<code>soggetti</code>) and its length (<code>soggetti_length</code>).
  Every time this function is ran, I realloc the size to make place for another pointer.
  Problem is, exactly the fifth time the function is called, I get:</p>
  <pre><code>realloc(): invalid next size
  </code></pre>
  <p>Do you know how can I do?
  I think I can exclude that the memory I realloc is not enough, I tried to increase it and nothing changes.
  Oh, and I debugged it with gdb, the function crashes BEFORE returning, so I don't even get something like a NULL return.</p>