title: Program crashes malloc/free, C
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int tablou(n)
  {
      int *buffer, i=0;
      buffer=(int*)malloc(n+1);
      if (buffer==NULL) exit(1);
      for(i=0; i&lt;=n; i++){
          buffer[i]=i;
      printf ("%d ", buffer[i]);
      }
      //free(buffer);
      //printf("%d ", n);
      return 0;
  }
  int main()
  {
      int n;
      printf("nr of elements:\n");
      scanf("%d", &amp;n);
      tablou(n);
      printf("Hello world!\n");
      return 0;
  }
  </code></pre>
  
  <p>it crashes at line 14: </p>
  
  <pre><code>free(buffer);
  </code></pre>
  
  <p>if I don't free the memory, the program gives an error after printing Hello world!
  if I free the memory, it gives an error before that.</p>