realloc(void *ptr, size_t new_size)
returns NULL
in two cases:
- If there is not enough memory, the old memory block is not freed and NULL is returned.
- NULL is also returned if error has occurred.
How do I know what type of problem occurred?
If we are short of memory, I might page some memory to disk.
How do I know whether I should do free(ptr)
? (maybe it was already freed by realloc).