From 78fc20489ca3d1347c642ae0a65db49934d1c02f Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 4 Jan 2024 15:45:05 -0500 Subject: [PATCH] Fix memory leaks in State_Chm%AerMass and State_Chm%Phot Headers/phot_container_mod.F90 - Deallocate the Phot object before setting it to NULL() Headers/state_chm_mod.F90 - Deallocate State_Chm%AerMass before setting it to NULL() CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca --- CHANGELOG.md | 3 ++- Headers/phot_container_mod.F90 | 1 + Headers/state_chm_mod.F90 | 7 ++++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5cd61272..8072f8daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Fixed - Fixed bug in stratospheric aerosols optical depths passed to Fast-JX - Restored consideration of both isSnow and isIce in dry deposition -- Fixed calculation of FRLAND_NOSNO_NOICE in `calc_met_mod.F90` +- Fixed calculation of `FRLAND_NOSNO_NOICE` in `calc_met_mod.F90` +- Fixed memory leaks in `State_Chm%AerMass` and `State_Chm%Phot` containers ### Added - Added interface to Cloud-J package for computing photolysis rates diff --git a/Headers/phot_container_mod.F90 b/Headers/phot_container_mod.F90 index 681034bf1..e317b4de9 100644 --- a/Headers/phot_container_mod.F90 +++ b/Headers/phot_container_mod.F90 @@ -758,6 +758,7 @@ SUBROUTINE Cleanup_Phot_Container( Phot, RC ) IF (ALLOCATED(Phot%RTASYMAER )) DEALLOCATE(Phot%RTASYMAER ) #endif + DEALLOCATE( Phot ) Phot => NULL() ENDIF diff --git a/Headers/state_chm_mod.F90 b/Headers/state_chm_mod.F90 index 2bdaeeed4..e45089f91 100644 --- a/Headers/state_chm_mod.F90 +++ b/Headers/state_chm_mod.F90 @@ -1020,7 +1020,7 @@ SUBROUTINE Init_State_Chm( Input_Opt, State_Chm, State_Grid, RC ) ! Save nAerosol to State_Chm State_Chm%nAeroType = nAerosol - !--------------------------------------------------------------------- + !--------------------------------------------------------------------- ! Aerosol object ! NOTE: content is currently not registered !--------------------------------------------------------------------- @@ -3063,8 +3063,8 @@ SUBROUTINE Cleanup_State_Chm( State_Chm, RC ) !======================================================================= ! Deallocate and nullify pointer fields of State_Chm !======================================================================= - IF ( ASSOCIATED ( State_Chm%Phot ) ) THEN - CALL Cleanup_Phot_Container(State_Chm%Phot, RC ) + IF ( ASSOCIATED( State_Chm%Phot ) ) THEN + CALL Cleanup_Phot_Container( State_Chm%Phot, RC ) State_Chm%Phot => NULL() ENDIF @@ -3212,6 +3212,7 @@ SUBROUTINE Cleanup_State_Chm( State_Chm, RC ) IF ( ASSOCIATED( State_Chm%AerMass ) ) THEN CALL Cleanup_AerMass_Container(State_Chm%AerMass, RC ) + DEALLOCATE( State_Chm%AerMass ) State_Chm%AerMass => NULL() ENDIF