Skip to content

Commit

Permalink
fixing more memory problems (#476)
Browse files Browse the repository at this point in the history
* removed IF (ASSOCIATED(CBUF)) because CBUF is undefined

* fix associated() check on undefind pointer in ixgb2()

* fixing some memory problems

* fixing some memory problems

* whitespace cleanup

* turn off printing in test that causes memory problems

* initialized local variable to solve memory issue

* fixed memory leak in test_files

* initialized array in gdt2gds() to solve memory problems

* fixed uninitialized memory in test_g2_encode

* fixed memory problem in test code

---------

Co-authored-by: Ed <edwardjameshartnett@gmail.com>
  • Loading branch information
edwardhartnett and edhartnett authored Jul 10, 2023
1 parent 2dccb65 commit c8f0e30
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/gdt2gds.f
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ subroutine gdt2gds(igds,igdstmpl,idefnum,ideflist,kgds,
integer :: kgds72(200),kgds71(200),idum(200),jdum(200)

iret=0
idum = 0
if (igds(5).eq.0) then ! Lat/Lon grid
kgds(1)=0
kgds(2)=igdstmpl(8) ! Ni
Expand Down
1 change: 1 addition & 0 deletions src/getfield.F90
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ subroutine getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, &
have7 = .false.
ierr = 0
numfld = 0
numlocal = 0

! Check for valid request number
if (ifldnum .le. 0) then
Expand Down
3 changes: 3 additions & 0 deletions tests/test_files.F90
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ program test_files
! Close the file.
call baclose(lugb, iret)
if (iret .ne. 0) stop 200

! Free memory.
call gf_free(gfld)

print *, 'SUCCESS!'
end program test_files
1 change: 1 addition & 0 deletions tests/test_g2_encode.F90
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ program test_g2_encode
integer :: i

print *, 'Testing g2 library encoding/decoding.'
fld = 1

print *, 'Testing g2 library encoding...'
! listsec0(1) Discipline-GRIB Master Table Number (Code Table 0.0)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_getgb2p.F90
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ end subroutine getgb2p
do i = 1, 250
jgdt(i) = -9999
end do
nullify(gribm)

print *, 'First try with extract true...'

extract = .true.
call getgb2p(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
extract, k, gribm, leng, iret)
print *, "done"
if (iret .ne. 0) stop 101
if (k .ne. 1 .or. leng .ne. 11183) stop 110

Expand Down
6 changes: 3 additions & 3 deletions tests/test_getgb2p_gdas.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ subroutine getgb2p(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
end subroutine getgb2p
end interface

print *, 'Testing the getgb2p() subroutine - expect and ignore error messages during test...'

! Open a real GRIB2 file.
print *, 'Testing getgb2p() some more...'
print *, 'Testing getgb2p() with file ', GDAS_FILE
call baopenr(lugb, GDAS_FILE, iret)
if (iret .ne. 0) stop 100

Expand All @@ -55,11 +53,13 @@ end subroutine getgb2p
do i = 1, 250
jgdt(i) = -9999
end do
extract = .false.

! Try with extract both true and false. The results are the same for
! the GDAS file.
do e = 1, 2
if (e .eq. 2) extract = .true.
print *, 'calling getgb2p() with extract = ', extract
call getgb2p(lugb, 0, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, &
extract, k, gribm, leng, iret)
print *, iret, k, leng
Expand Down
2 changes: 1 addition & 1 deletion tests/test_index_gdas.F90
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ end subroutine getgb2s
call getgb2s(cbuf, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
jgdt, k, gfld, lpos, iret)
if (iret .ne. 0) stop 201
call print_gribmod(gfld)
! call print_gribmod(gfld)
print *, '***************************************'
if (cmp_gribmod(gfld, expected_gfld(mnum)) .ne. 0) stop 202
print *, '***************************************'
Expand Down

0 comments on commit c8f0e30

Please sign in to comment.