Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5116 Discussions

Memory errors and leaks in Fortran code

jirina
New Contributor I
981 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
981 Views
I think the thread needs to be moved to Intel Visual Fortran Compiler Forum to help jirina. Thanks.
0 Kudos
Mark_D_Intel
Employee
980 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.

0 Kudos
jirina
New Contributor I
980 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.

0 Kudos
Reply