Analyzers
Support for Analyzers (Intel VTune™ Profiler, Intel Advisor, Intel Inspector)
Announcements
Intel Customer Support will be observing the Martin Luther King holiday on Monday, Jan. 17, and will return on Tues. Jan. 18.
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646

Memory errors and leaks in Fortran code

jirina
Novice
176 Views

I ran "Memory Error Analysis / Detect Leaks" on my Fortran code (fixed form) and Inspector reported several problems that I don't understand:

1. Kernel resource leak in the following piece of code:

use ifport

character*1024 arg0
character*1024 filename
character*16 dllname

character(3) drive
character(256) dir, name, ext, file

integer*4 length

integer (kind=int_ptr_kind()) handle
type (file$info) info

call getarg ( 0, arg0 )

length = SPLITPATHQQ ( arg0, drive, dir, name, ext )

dllName = 'myDLL.dll'

filename = drive(1:len_trim(drive)) // dir(1:len_trim(dir)) // trim(dllName)

handle = FILE$FIRST
if ( GETFILEINFOQQ(filename, info, handle) .gt. 0 ) then
...
endif

The kernel resource leak is reported for the line with the function GETFILEINFOQQ; I wonder what I am doing wrong. Is it the size of filename, being character*1024 ?

2. Memory leak or Uninitialized partial memory access in the last line of the code

use ifport

integer(2) status

status = DELFILESQQ('myFile.dat')

By the way, the example in the documentation for the function DELFILESQQ declares the results of the function as integer(4), could this be any problem that integer(2) as the results of the function is assigned to integer(4) variable?

3. Invalid partial memory access or Uninitialized partial memory access in multiple locations:

integer*4 iunx_ew, iunx, ios, iocheck, rcl

character*20 file_ew_text, finame

OPEN ( iunx_ew, FILE=file_ew_text, ACCESS='SEQUENTIAL', ACTION='WRITE', SHARE='DENYWR', IOSTAT=ios )

OPEN ( 99, FILE='myDB.d', ACCESS='DIRECT', STATUS='OLD', RECL=520, IOSTAT=iocheck, SHARE='DENYWR' )

OPEN ( iunx, FILE=finame, ACCESS='DIRECT', RECL=rcl, IOSTAT=iocheck, SHARE='DENYWR' )

All the lines with the OPEN statement exhibit the memory access problem. Why?

0 Kudos
3 Replies
SergeyKostrov
Valued Contributor II
176 Views
I think the thread needs to be moved to Intel Visual Fortran Compiler Forum to help jirina. Thanks.
Mark_D_Intel
Employee
176 Views

1. From the documentation for GETFILEINFOQQ:

 "GETFILEINFOQQ must be called with the handle until GETFILEINFOQQ sets handle to FILE$LAST, or system resources may be lost"

2. This looks like it occurs inside the implementation of DELFILESQQ.  This is a false positive and can be ignored.

3. Assuming the file name  and unit number variables are defined, these are false positives occuring inside OPEN, and can be ignored.

You can use the suppression feature to remove future reporting of these problems.

jirina
Novice
176 Views

The proper coding of GETFILEINFOQQ based on the documentation helped me to get rid of the memory error. Thank you!

I will be looking at the suppression feature later; I don't have so many false positives in my application.

Reply