Factor out uid/gid allocation to next_free_id()