  Magnetic fields in upper main-sequence stars, white dwarfs, and neutron stars
are known to persist for timescales comparable to their lifetimes. From a
theoretical perspective this is problematic, as it can be shown that simple
magnetic field configurations are always unstable. In non-barotropic stars,
stable stratification allows for a much wider range of magnetic field
structures than in barotropic stars, and helps stabilize them by making it
harder to induce radial displacements. Recent simulations by Braithwaite and
collaborators have shown that, in stably stratified stars, random initial
magnetic fields evolve into nearly axisymmetric configurations with both
poloidal and toroidal components, which then remain stable for some time. It is
desirable to provide an analytic study of the stability of such fields. We
write an explicit expression for a plausible equilibrium structure of an
axially symmetric magnetic field with both poloidal and toroidal components of
adjustable strengths, in a non-barotropic static fluid star, and study its
stability using the energy principle. We construct a displacement field that
should be a reasonable approximation to the most unstable mode of a toroidal
field, and confirm Braithwaite's result that a given toroidal field can be
stabilized by a poloidal field containing much less energy than the former.
This is consistent with the speculation that the toroidal field is the main
reservoir powering magnetar activity. The deformation of a neutron star caused
by the hidden toroidal field can also cause emission of gravitational waves.
