I think that closed-cell foam should be OK.
Open-cell foam attracts moisture and retains it, which isn't good for metal, not even "stainless" steel.
Closed-cell foam has open cells only on its very surface, which I believe might be less water-retaining than woven cotton.
In any case, I always leave my stored guns coated with a preservative. In the short term, oil is OK. In the long term, Boeshield (from Brownells) is better.
Silicone-impregnated sleeves are also good, short-term. Rust-preventing plastic sleeves are better for the long term.