Is the compiler allowed to recycle freed pointer variables?

Upon an object reaching the end of its lifetime, all pointers to it become indeterminate. This applies to block-scope variables and to malloced memory just the same. The applicable clause is, in C11, 6.2.4:2. The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. … Read more

free char*: invalid next size (fast) [duplicate]

Your code is wrong. You are allocating space for a single pointer (malloc(sizeof(char*))), but no characters. You are overwriting your allocated space with all the strings, causing undefined behavior (in tihs particular case, corrupting malloc()‘s book-keeping data). You don’t need to allocate space for the pointer (res), it’s a local variable. You must allocate space … Read more