title: Simple test of malloc and free with int pointer causes double free or corruption error
body: <p>To learn more about pointers I wrote just a simple test function which creates a pointer, allocates space ande after some output on the shell the space shall be freed.</p>
  
  <pre><code>void main() {
    int *p = (int*) malloc(sizeof(int));
    int a = 42;
    printf("p: %x\n", p);
    printf("*p: %d\n", *p);
    printf("a: %s\n", a);
    printf("&amp;a: %x\n", &amp;a);
    p = &amp;a;
    printf("p: %x\n", p);
    printf("*p: %x\n", *p);
  
    //Until now everything works as expected
    free(p); //ERROR
    // printf("p: %x\n", p); // Shall cause error, because space was freed
    // printf("*p: %x\n", *p); // Shall cause error, because space was freed
  }
  </code></pre>
  
  <p>At first runs everything was ok. free(p) caused no error. Then I tried the same test with a struct and got the double free error. "Ok, maybe I do something wrong, lets go to the start", I thought and Ctrl+Z everything to this one above, like it was before. Now I still get this error. Why? Thats a newbie question, I know. The code above you can find everywhere in the web as a simple demonstration of malloc and free. Like here: <a href="http://www.cplusplus.com/reference/cstdlib/free/" rel="nofollow">http://www.cplusplus.com/reference/cstdlib/free/</a>
  Hope, someone can tell me what I do wrong.</p>