This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[patch,libgfortran] Fix PR27360 Memory leak in read_logical


:ADDPATCH fortran:

The attached patch fixes the problem which I confirmed with valgrind. I failed to free the line_buffer in all the code paths when I revised read_logical before.

I intend to commit this patch under the obvious and simple rule to trunk and then 4.1 branch tomorrow.

My apologies for missing this before.

Jerry

2006-04-29 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR libgfortran/27360
	
	* io/list_read.c (read_logical):  Free line_buffer and free saved.
Index: io/list_read.c
===================================================================
*** io/list_read.c	(revision 113213)
--- io/list_read.c	(working copy)
*************** read_logical (st_parameter_dt *dtp, int 
*** 652,657 ****
--- 652,658 ----
    dtp->u.p.item_count = 0;
    dtp->u.p.line_buffer_enabled = 0;
    set_integer ((int *) dtp->u.p.value, v, length);
+   free_line (dtp);
  
    return;
  
*************** read_logical (st_parameter_dt *dtp, int 
*** 689,713 ****
  
   bad_logical:
  
    if (nml_bad_return (dtp, c))
      return;
  
    eat_line (dtp);
    free_saved (dtp);
-   if (dtp->u.p.line_buffer != NULL)
-     free_mem (dtp->u.p.line_buffer);
    st_sprintf (message, "Bad logical value while reading item %d",
  	      dtp->u.p.item_count);
    generate_error (&dtp->common, ERROR_READ_VALUE, message);
    return;
  
   logical_done:
!   
    dtp->u.p.item_count = 0;
    dtp->u.p.line_buffer_enabled = 0;
    dtp->u.p.saved_type = BT_LOGICAL;
    dtp->u.p.saved_length = length;
    set_integer ((int *) dtp->u.p.value, v, length);
  }
  
  
--- 690,716 ----
  
   bad_logical:
  
+   free_line (dtp);
+ 
    if (nml_bad_return (dtp, c))
      return;
  
    eat_line (dtp);
    free_saved (dtp);
    st_sprintf (message, "Bad logical value while reading item %d",
  	      dtp->u.p.item_count);
    generate_error (&dtp->common, ERROR_READ_VALUE, message);
    return;
  
   logical_done:
! 
    dtp->u.p.item_count = 0;
    dtp->u.p.line_buffer_enabled = 0;
    dtp->u.p.saved_type = BT_LOGICAL;
    dtp->u.p.saved_length = length;
    set_integer ((int *) dtp->u.p.value, v, length);
+   free_saved (dtp);
+   free_line (dtp);
  }
  
  

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