Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

GETFILEINFOQQ and valgrind

David_Kinniburgh
Beginner
472 Views

I'm new to valgrind and have been hunting down possible memory leaks. I ran valgrind on the ifort example file for GETFILEINFOQQ (see below) which reports the size of one or more files. I'm running on Ubuntu 17.10 in VirtualBox.

PROGRAM fileinfo

CALL SHOWPERMISSION( )

END PROGRAM fileinfo

!################################################################

! SUBROUTINE to demonstrate GETFILEINFOQQ
SUBROUTINE SHOWPERMISSION( )
USE IFPORT
  CHARACTER(80) files
  INTEGER(KIND=INT_PTR_KIND( )) handle
  INTEGER(4) length
  CHARACTER(5) permit
  TYPE (FILE$INFO) info
    WRITE (*, 900) ' Enter wildcard of files to view: '
    900 FORMAT (A, \)

    length = GETSTRQQ(files)
    handle = FILE$FIRST

    DO WHILE (.TRUE.)
      length = GETFILEINFOQQ(files, info, handle)
      IF ((handle .EQ. FILE$LAST) .OR. &
          (handle .EQ. FILE$ERROR)) THEN
         SELECT CASE (GETLASTERRORQQ( ))
           CASE (ERR$NOMEM)
             WRITE (*,*) 'Out of memory'
           CASE (ERR$NOENT)
             EXIT
           CASE DEFAULT
             WRITE (*,*) 'Invalid file or path name'
         END SELECT
      END IF

      permit = ' '
      IF ((info%permit .AND. FILE$HIDDEN) .NE. 0) &
         permit(1:1) = 'H'
      IF ((info%permit .AND. FILE$SYSTEM) .NE. 0) &
         permit(2:2) = 'S'
      IF ((info%permit .AND. FILE$READONLY) .NE. 0) &
         permit(3:3) = 'R'
      IF ((info%permit .AND. FILE$ARCHIVE) .NE. 0) &
         permit(4:4) = 'A'
      IF ((info%permit .AND. FILE$DIR) .NE. 0) &
         permit(5:5) = 'D'
      WRITE (*, 9000) TRIM(info%name), info%length, permit
      9000 FORMAT (1X, A, 1X, I9, ' ', A6)
    END DO
END SUBROUTINE
  1. $ifort -v
  2. ifort version 18.0.1
  3. $ifort -g -traceback -o fileinfo fileinfo.f90
  4. $ls -l

-rwxr-xr-x 1 david david 832912 Feb  4 23:19 fileinfo
-rw-r--r-- 1 david david   1436 Feb  4 22:57 fileinfo.f90

        5. $valgrind --tool=memcheck -v --leak-check=full --show-leak-kinds=all --track-origins=yes ./fileinfo

       Enter wildcard of files to view: *.f90

       fileinfo.f90     1436

valgrind reports some 32 kB as 'definitely lost'. Is this something to be concerned about?

<pre>

==7394== HEAP SUMMARY:
==7394==     in use at exit: 33,088 bytes in 3 blocks
==7394==   total heap usage: 14 allocs, 11 frees, 79,719 bytes allocated
==7394== 
==7394== Searching for pointers to 3 not-freed blocks
==7394== Checked 470,400 bytes
==7394== 
==7394== 32 bytes in 1 blocks are still reachable in loss record 1 of 3
==7394==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7394==    by 0x53B282E: _dlerror_run (dlerror.c:141)
==7394==    by 0x53B2197: dlsym (dlsym.c:70)
==7394==    by 0x41FF7E: real_aio_init (in /home/david/projects//fortran/fileinfo)
==7394==    by 0x4095DB: for__once_private (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x4077F4: for_rtl_init_ (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x402C38: main (in /home/david/projects/fortran/fileinfo)
==7394== 
==7394== 240 bytes in 1 blocks are still reachable in loss record 2 of 3
==7394==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7394==    by 0x40A2DD: for__get_vm (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x408E26: for__access_threadstor_threads (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x403CD9: for_errsns_load (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x403410: getfileinfoqq_ (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x402D79: showpermission_ (fileinfo.f90:24)
==7394==    by 0x402C6A: MAIN__ (fileinfo.f90:3)
==7394==    by 0x402C3D: main (in /home/david/projects/fortran/fileinfo)
==7394== 
==7394== 32,816 bytes in 1 blocks are definitely lost in loss record 3 of 3
==7394==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7394==    by 0x5688E21: __alloc_dir (opendir.c:218)
==7394==    by 0x5688E21: opendir_tail (opendir.c:136)
==7394==    by 0x5688E21: opendir (opendir.c:191)
==7394==    by 0x40313A: getfileinfoqq_ (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x402D79: showpermission_ (fileinfo.f90:24)
==7394==    by 0x402C6A: MAIN__ (fileinfo.f90:3)
==7394==    by 0x402C3D: main (in /home/david/projects/fortran/fileinfo)
==7394== 
==7394== LEAK SUMMARY:
==7394==    definitely lost: 32,816 bytes in 1 blocks
==7394==    indirectly lost: 0 bytes in 0 blocks
==7394==      possibly lost: 0 bytes in 0 blocks
==7394==    still reachable: 272 bytes in 2 blocks
==7394==         suppressed: 0 bytes in 0 blocks

</pre>

 

It also reported some 'Conditional jump or move depends on uninitialised value(s)', e.g.

<pre>

==7394== Conditional jump or move depends on uninitialised value(s)
==7394==    at 0x48735D: __intel_sse2_strcpy (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x440B2D: for__add_to_lf_table (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x45791C: for__open_proc (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x447B65: for__open_default (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x40B93E: for_write_seq_fmt (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x402CF8: showpermission_ (fileinfo.f90:17)
==7394==    by 0x402C6A: MAIN__ (fileinfo.f90:3)
==7394==    by 0x402C3D: main (in /home/david/projects/fortran/fileinfo)
==7394==  Uninitialised value was created by a heap allocation
==7394==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7394==    by 0x40A2DD: for__get_vm (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x45607E: for__open_proc (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x447B65: for__open_default (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x40B93E: for_write_seq_fmt (in /home/david/projects/fortran/fileinfo)
==7394==    by 0x402CF8: showpermission_ (fileinfo.f90:17)
==7394==    by 0x402C6A: MAIN__ (fileinfo.f90:3)
==7394==    by 0x402C3D: main (in /home/david/projects/fortran/fileinfo)

</pre>

Again, should this be of concern?

 

     

     

     

    0 Kudos
    0 Replies
    Reply