title: Malloc space not accessible after another apparently indipendent function
body: <p>I have a problem with malloc in the following change() function. When i = 5, when I read and trying to save the input line in s, the table[4] change and the debugger says: &quot;&lt;error: Cannot access memory at address 0xa696573&gt;&quot;, even if before the value was correct. The same problem occurs using scanf instead of fgets or printing the table[3] value.</p>
  <p>(I'm using <code>gcc -std=gnu11 -g</code> to compile and gdb for debugging in VS Code on Ubuntu in Linux subsystem in Windows 10)</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  char **table;
  
  int change()
  {
      char s[1025];
      for(int i = 0; i &lt;= 6; i++)
      {
          fgets(s, 1024, stdin);
          //scanf(&quot; %1024[^\n]%*c&quot;, s);
          table[i] = (char *) malloc(strlen(s) + 1);
          strcpy(table[i], s);
      }
  }
  
  int main()
  {
      table = malloc(10);
      change();
      return 0;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DXRbw.png" rel="nofollow noreferrer">values before reading sixth (i=5) line</a></p>
  <p><a href="https://i.stack.imgur.com/0F16C.png" rel="nofollow noreferrer">values after reading sixth (i=5) line</a></p>