Cosmological upper bound on heavy-neutrino lifetimes