Handle errors from realloc