Skip to content

Commit 94aa27a

Browse files
authored
Fix memory leaks identified by a PGI compiler (#2139)
TYPE: bug fix KEYWORDS: Memory Leaks SOURCE: Charlie Li - Software developer from lakes environmental Canada DESCRIPTION OF CHANGES: Problem: Memory leaks are detected in wrf_timeseries.F and start_em.F when use PGI option: -g -O0 -traceback -Mchkptr -Mbounds -Ktrap=fp -Msave -tp=px It will failed for: "0: ALLOCATE: array already allocated" 1. In dyn_em/start_em.F, dz8w is allocated, but not deallocated. 2. In share/wrf_timeseries.F, two arrays, earth_u_profile and earth_v_profile, are allocated without being deallocated when time series is not computed. Solution: Calls to deallocate the array dz8w is added in start_em.F, and move the return statement before array allocation in wrf_timeseries.F. LIST OF MODIFIED FILES: M share/wrf_timeseries.F M dyn_em/start_em.F TESTS CONDUCTED: The Jenkins tests are all passing. RELEASE NOTE: This PR fixed memory leaks related to arrays being allocated without being deallocated in start_em and time series calculation subroutines.
1 parent a0144bd commit 94aa27a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

dyn_em/start_em.F

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,7 @@ SUBROUTINE start_domain_em ( grid, allowed_to_read &
20012001
#endif
20022002
20032003
DEALLOCATE(z_at_q)
2004+
DEALLOCATE(dz8w)
20042005
20052006
IF (config_flags%p_lev_diags == PRESS_DIAGS ) THEN
20062007
CALL wrf_debug ( 200 , ' PLD: pressure level diags' )

share/wrf_timeseries.F

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,21 @@ SUBROUTINE calc_ts( grid )
351351
! FALSE to output T and Q at 2-m and wind at 10-m diagnostic levels:
352352
LOGICAL, PARAMETER :: ts_model_level = .FALSE.
353353

354+
IF ( grid%ntsloc_domain .LE. 0 ) THEN
355+
RETURN
356+
END IF
357+
358+
#if ((EM_CORE == 1) && (DA_CORE != 1))
359+
IF ( grid%dfi_opt /= DFI_NODFI .AND. grid%dfi_stage /= DFI_FST ) THEN
360+
RETURN
361+
END IF
362+
#endif
363+
354364
!Allocate the arrays for wind components
355365
#if ( EM_CORE == 1 )
356366
ALLOCATE ( earth_u_profile(grid%max_ts_level), earth_v_profile(grid%max_ts_level) )
357367
#endif
358368

359-
IF ( grid%ntsloc_domain .LE. 0 ) RETURN
360-
361-
#if ((EM_CORE == 1) && (DA_CORE != 1))
362-
IF ( grid%dfi_opt /= DFI_NODFI .AND. grid%dfi_stage /= DFI_FST ) RETURN
363-
#endif
364-
365369
n = grid%next_ts_time
366370

367371
ALLOCATE(p8w(grid%sm32:grid%em32))

0 commit comments

Comments
 (0)