call realloc only if necessary