[patch,libgfortran] PR88776 Namelist read from stdin: loss of data

Jerry DeLisle jvdelisle@charter.net
Mon Jan 14 00:18:00 GMT 2019


On 1/12/19 2:35 PM, Jerry DeLisle wrote:
> Hi all,
> 
> As stated in the PR, the problem turns out to be an ungraceful return 
> after an error.  Most namelist errors go through nml_err_ret, The one I 
> am removing did not and in the unique case of UNIT=5 after the error it 
> falls through and hits some code which modifies pointers to the namelist 
> data structures.
> 
> This patch fixes it.
> 
> Regression tested on x86-64 and manually tested with a redirection to 
> stdin. (cat somefile | ./a.out )
> 
> I plan to commit today as simple along with a new testcase.
> 
> Regards.
> 
> Jerry
> 
> 2019-01-12  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
> 
>      PR libfortran/88776
>      * io/list_read.c (namelist_read): Use nml_err_ret path on
>      read error, not based on stdin_unit.

Committed.

While doing extra testing on the test case for this PR, I noticed a 
memory leak with valgrind.

The attached patch fixes this. The problem is when opening a file with a 
preconnected unit, the previously initialized format buffer (fbuf) in 
the preconnected unit structure gets abandoned (pointer overwritten by 
the new fbuf), and a new one allocated later in the code path.

I will commit this additional patch and the test case as simple and obvious.

Regression tested on x86_64. Valgrind clean.

Regards,

Jerry

2019-01-13  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

    PR libfortran/88776
    * io/open.c (newunit): Free format buffer if the unit specified is
    for stdin, stdout, or stderr.

2019-01-13  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

    PR libfortran/88776
    * gfortran.dg/namelist_96.f90: New test.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr88776a.diff
Type: text/x-patch
Size: 694 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190114/85b8eb93/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: namelist_96.f90
Type: text/x-fortran
Size: 1069 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20190114/85b8eb93/attachment-0001.bin>


More information about the Fortran mailing list