You seem to somehow have a mental model where you expect pointers to be magically supervised, so that one pointer shold "know" what happens to another.
That's not how pointers, or the C memory model, work at all.
There is no connection between different pointers. If two pointers point at the same address, and you free()
one of them, the other one becomes invalid but it's value doesn't change. Neither does the value of the first; it's just that dereferencing either of them just became an invalid thing to do.
Consider this:
int *a = malloc(sizeof *a);
if(a != NULL)
{
int *b = a;
*a = 4711;
printf("a=%p\nb=%p\n", (void *) a, (void *) b);
free(b); /* same pointer that malloc() returned, this is fine */
printf("a=%p\nb=%p\n", (void *) a, (void *) b);
}
The above will print the same address four times, since the value of any of the pointers doesn't change just because you call free()
on one of them. Remember that free()
is not magic, it's just a function. There is no special hidden functionality with it, you can write your own malloc()
and free()
if you feel like it and get the exact same semantics.