| 28 | #include "compat.h" |
| 29 | |
| 30 | void * |
| 31 | reallocf(void *ptr, size_t size) |
| 32 | { |
| 33 | void *nptr; |
| 34 | |
| 35 | nptr = realloc(ptr, size); |
| 36 | |
| 37 | /* |
| 38 | * When the System V compatibility option (malloc "V" flag) is |
| 39 | * in effect, realloc(ptr, 0) frees the memory and returns NULL. |
| 40 | * So, to avoid double free, call free() only when size != 0. |
| 41 | * realloc(ptr, 0) can't fail when ptr != NULL. |
| 42 | */ |
| 43 | if (!nptr && ptr && size != 0) |
| 44 | free(ptr); |
| 45 | return (nptr); |
| 46 | } |
no test coverage detected