Next: , Previous: , Up: ISO C and POSIX Function Substitutes   [Contents][Index]


10.906 realloc

POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html

Gnulib module: realloc-posix

Portability problems fixed by Gnulib:

Without the ‘realloc-gnu’ module described below, it is not portable to call realloc with a size of 0. With a NULL pointer argument, this is the same ambiguity as malloc (0) on whether a unique zero-size object is created. With a non-NULL pointer argument p, C17 says that it is implementation-defined whether realloc (p, 0) frees p. Behavior varies on whether realloc (p, 0) always frees p and successfully returns a null pointer, or always fails and leaves p valid, or usually succeeds and returns a unique zero-size object; a program not suspecting these variations in semantics will leak memory (either the still-valid p, or the non-NULL return value).

Extension: Gnulib provides a module ‘realloc-gnu’ that substitutes a realloc implementation that behaves more like the glibc implementation. It fixes these portability problems: