...
If realloc() is called with size equal to 0, then if a NULL pointer is returned, the old value should be unchanged. However, there are some common but non-conforming implementations that free the pointer, which means that calling free on the original pointer might result in a double-free vulnerability. However, not calling free on the original pointer might result in a memory leak.
See Implementation-Specific 7.35 Performing zero length allocations (MEM04-C) for more information.
Compliant Code Example (realloc())
...