Skip to content

flux_src_n energy-slot deallocation lacks the chemistry guard its allocation has #1908

Description

@sbryngelson

In src/simulation/m_rhs.fpp the energy slot of flux_src_n is allocated for the chemistry-diffusion path inside if (chemistry):

if (chemistry) then
    ...
    if (chem_params%diffusion .and. .not. (viscous .or. surface_tension .or. heat_conduction)) then
        @:ALLOCATE(flux_src_n(i)%vf(eqn_idx%E)%sf(...))
    end if
end if

but the matching deallocation in s_finalize_rhs_module tests only the inner condition:

if (chem_params%diffusion .and. .not. (viscous .or. surface_tension .or. heat_conduction)) then
    @:DEALLOCATE(flux_src_n(i)%vf(eqn_idx%E)%sf)
end if

chemistry is a compile-time Fypp constant while chem_params%diffusion is read from the namelist, so a non-chemistry build whose input sets chem_params%diffusion = T would reach the deallocation for a pointer that was never allocated.

Whether that is reachable depends on whether input validation rejects chem_params%diffusion in a non-chemistry build — I did not chase that down. Either way the two guards should match: the deallocation should carry the same chemistry condition its allocation does.

Found while adding Fourier heat conduction (#1906); unrelated to that change. The heat_conduction term in both conditions is from that PR, but the asymmetry predates it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions