if called with size 0, realloc frees the buffer, which may eventually lead to a double free corruption.