https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128721

            Bug ID: 128721
           Summary: Asynchronous I/O leaks parameter blocks and
                    descriptors of statements skipped after an error
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: suvarchal.cheedela at awi dot de
  Target Milestone: ---

Created attachment 66163
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66163&action=edit
program to show memory leak

When an asynchronous statement fails, the I/O thread skips the queue items
that follow.  For skipped AIO_DATA_TRANSFER_INIT items it does not free the
parameter block, for skipped AIO_TRANSFER_ARRAY items not the copied
descriptor, and it unlocks io_lock for skipped AIO_*_DONE items whose init
never locked it (async_io in libgfortran/io/async.c).  Also present on
trunk (17.0.0 20261113). 
$ gfortran -g -pthread -fsanitize=leak error_leak.f90 && ./a.out
done
SUMMARY: LeakSanitizer: 9376 byte(s) leaked in 112 allocation(s).

(The number varies with how many statements are queued when the error
is seen, between about 100 and 300 blocks.)

--- error_leak.f90 ---
! Statements queued behind a failing asynchronous READ are skipped.  Build
! with -fsanitize=leak: stock gfortran leaks the parameter block and the
! array descriptors of every skipped statement (about 300 blocks here).
program error_leak
  implicit none
  integer, parameter :: n = 2000000
  real, allocatable, asynchronous :: a(:)
  real, asynchronous :: b(100), c(100)
  integer :: i, ios, nerr
  allocate (a(n))
  a = 1.0
  open (10, file='error_leak.dat', form='unformatted', &
        asynchronous='yes', status='replace')
  write (10) a
  rewind (10)
  a = 0.0
  nerr = 0
  read (10, asynchronous='yes', iostat=ios) a
  if (ios /= 0) nerr = nerr + 1
  do i = 1, 100
    read (10, asynchronous='yes', iostat=ios) b, c
    if (ios /= 0) nerr = nerr + 1
  end do
  wait (10, iostat=ios)
  if (ios /= 0) nerr = nerr + 1
  if (nerr == 0) stop 1
  if (any (a /= 1.0)) stop 2
  rewind (10)
  b = 0.0
  read (10, asynchronous='yes') b
  wait (10)
  if (any (b /= 1.0)) stop 3
  close (10, status='delete')
  deallocate (a)
  print '(a)', 'done'
end program error_leak

Reply via email to