The stability of primordial magnetic fields produced by phase transitions