Does realloc free the former buffer if it fails?
No, it does not. That aspect has often annoyed me since you can’t just use: if ((buff = realloc (buff, newsize)) == NULL) return; in your code if you want to free the original on failure. Instead you have to do something like: if ((newbuff = realloc (buff, newsize)) == NULL) { free (buff); return; … Read more