This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] Runtime memory leak checking.


Dear Janus,

Do please get on with fixing the bugs - I will replace the hashtable.


> implicit none
> character(100), save :: path_To_Input='../test.dat'
> logical :: ex
> Inquire(file=trim(path_to_Input),exist=ex)
> print *,ex
> end
>
> with the following message:
>
> Error in memory deallocation at line 4 of source file 'test.f90':
> freeing memory that has not been allocated by us.
>
> *******************************
>
> Cheers,
> Janus
>
>
>
>
>
> 2008/11/29 Paul Richard Thomas <paul.richard.thomas@gmail.com>:
>> This patch is almost entirely due to FX Coudert; I added the updating
>> of gfc_current_locus in trans.c, the testcase and the ChangeLogs. ?I
>> also corrected one error.
>>
>> The patch implements checking for memory leaks, such that:
>>
>> [prt@localhost mem-check]# cat m*.f90
>> ! { dg-do run }
>> ! { dg-options = "-fruntime-check=memleaks" }
>> !
>> ! Test the runtime check for memory leaks.
>> !
>> ?integer(4), pointer :: i(:)
>> ?allocate (i(10))
>> end
>> ! { dg-output "found 1 memory leaks" }
>>
>> [prt@localhost mem-check]# /irun/bin/gfortran -static
>> -fruntime-check=memleaks m*.f90;./a.out
>>
>>
>> Fortran runtime checking: found 1 memory leaks
>> ?- at line 7 of file 'mem_check_1.f90', allocation of 40.0 B (address
>> 0x1749ee0)
>>
>> Peak user-allocated memory: 40.0 B
>> Peak memory created by the compiler for temporaries: 0.00 B
>>
>> When applied to some of the allocatable component testcases, such as:
>> [prt@localhost mem-check]# /irun/bin/gfortran -static
>> -fruntime-check=memleaks
>> /svn/trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_5.f90;./a.out
>>
>>
>> Fortran runtime checking: found 1 memory leaks
>> ?- at line 25 of file
>> '/svn/trunk/gcc/testsuite/gfortran.dg/alloc_comp_basics_5.f90',
>> allocation of 40.0 B (address 0x24fdee0)

This comes about because of

MAIN__ ()
{
  logical(kind=4) ex;
  static character(kind=1) path_to_input[1:100] = "../test.dat
                                                                       ";
  static integer(kind=4) options.0[8] = {68, 255, 0, 0, 0, 1, 0, 1};

  _gfortran_set_options (8, (void *) &options.0);
  {
    integer(kind=4) len.3;
    character(kind=1) * pstr.2;
    struct __st_parameter_inquire inquire_parm.1;

    inquire_parm.1.common.filename = &"testc.f90"[1]{lb: 1 sz: 1};
    inquire_parm.1.common.line = 4;
    _gfortran_string_trim (&len.3, (void * *) &pstr.2, 100, &path_to_input);
    inquire_parm.1.file = pstr.2;
    inquire_parm.1.file_len = len.3;
    inquire_parm.1.exist = (integer(kind=4) *) &ex;
    inquire_parm.1.flags2 = 0;
    inquire_parm.1.common.flags = 16512;
    inquire_parm.1.common.unit = 0;
    _gfortran_st_inquire (&inquire_parm.1);
    if (len.3 > 0)
      {
        {
          void * D.640;

          D.640 = (void *) pstr.2;
          if (D.640 != 0B)
            {
              __builtin_free (D.640);
            }
        }
      }
  }
  {
    struct __st_parameter_dt dt_parm.4;

    dt_parm.4.common.filename = &"testc.f90"[1]{lb: 1 sz: 1};
    dt_parm.4.common.line = 5;
    dt_parm.4.common.flags = 128;
    dt_parm.4.common.unit = 6;
    _gfortran_st_write (&dt_parm.4);
    _gfortran_transfer_logical (&dt_parm.4, &ex, 4);
    _gfortran_st_write_done (&dt_parm.4);
  }
}

_gfortran_string_trim not being in the memory check scheme - in
consequence the  replaced __builtin_free generates the error.

Cheers

Paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]