From 1f161c48edf27eac74ceff8ccf73d232f14b7009 Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Mon, 28 May 2018 21:55:31 +0000 Subject: [PATCH] re PR fortran/85840 (Memory leak in write.c) 2018-05-28 Jerry DeLisle PR libgfortran/85840 * io/write.c (write_real, write_real_g0, write_complex): Use separate local variables for the float string length. From-SVN: r260851 --- libgfortran/ChangeLog | 6 ++++++ libgfortran/io/write.c | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index eeb25f9cbb5..c0b0f859711 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2018-05-28 Jerry DeLisle + + PR libgfortran/85840 + * io/write.c (write_real, write_real_g0, write_complex): Use + separate local variables for the float string length. + 2018-05-26 Jerry DeLisle PR libgfortran/85906 diff --git a/libgfortran/io/write.c b/libgfortran/io/write.c index 5d52fd6914f..dc6a234f42e 100644 --- a/libgfortran/io/write.c +++ b/libgfortran/io/write.c @@ -1682,7 +1682,7 @@ write_real (st_parameter_dt *dtp, const char *source, int kind) char buf_stack[BUF_STACK_SZ]; char str_buf[BUF_STACK_SZ]; char *buffer, *result; - size_t buf_size, res_len; + size_t buf_size, res_len, flt_str_len; int orig_scale = dtp->u.p.scale_factor; dtp->u.p.scale_factor = 1; set_fnode_default (dtp, &f, kind); @@ -1697,8 +1697,8 @@ write_real (st_parameter_dt *dtp, const char *source, int kind) buffer = select_buffer (dtp, &f, precision, buf_stack, &buf_size, kind); get_float_string (dtp, &f, source , kind, 1, buffer, - precision, buf_size, result, &res_len); - write_float_string (dtp, result, res_len); + precision, buf_size, result, &flt_str_len); + write_float_string (dtp, result, flt_str_len); dtp->u.p.scale_factor = orig_scale; if (buf_size > BUF_STACK_SZ) @@ -1717,7 +1717,7 @@ write_real_g0 (st_parameter_dt *dtp, const char *source, int kind, int d) char buf_stack[BUF_STACK_SZ]; char str_buf[BUF_STACK_SZ]; char *buffer, *result; - size_t buf_size, res_len; + size_t buf_size, res_len, flt_str_len; int comp_d; set_fnode_default (dtp, &f, kind); @@ -1741,8 +1741,8 @@ write_real_g0 (st_parameter_dt *dtp, const char *source, int kind, int d) buffer = select_buffer (dtp, &f, precision, buf_stack, &buf_size, kind); get_float_string (dtp, &f, source , kind, comp_d, buffer, - precision, buf_size, result, &res_len); - write_float_string (dtp, result, res_len); + precision, buf_size, result, &flt_str_len); + write_float_string (dtp, result, flt_str_len); dtp->u.p.g0_no_blanks = 0; if (buf_size > BUF_STACK_SZ) @@ -1767,7 +1767,7 @@ write_complex (st_parameter_dt *dtp, const char *source, int kind, size_t size) char str1_buf[BUF_STACK_SZ]; char str2_buf[BUF_STACK_SZ]; char *buffer, *result1, *result2; - size_t buf_size, res_len1, res_len2; + size_t buf_size, res_len1, res_len2, flt_str_len1, flt_str_len2; int width, lblanks, orig_scale = dtp->u.p.scale_factor; dtp->u.p.scale_factor = 1; @@ -1790,18 +1790,18 @@ write_complex (st_parameter_dt *dtp, const char *source, int kind, size_t size) buffer = select_buffer (dtp, &f, precision, buf_stack, &buf_size, kind); get_float_string (dtp, &f, source , kind, 0, buffer, - precision, buf_size, result1, &res_len1); + precision, buf_size, result1, &flt_str_len1); get_float_string (dtp, &f, source + size / 2 , kind, 0, buffer, - precision, buf_size, result2, &res_len2); + precision, buf_size, result2, &flt_str_len2); if (!dtp->u.p.namelist_mode) { - lblanks = width - res_len1 - res_len2 - 3; + lblanks = width - flt_str_len1 - flt_str_len2 - 3; write_x (dtp, lblanks, lblanks); } write_char (dtp, '('); - write_float_string (dtp, result1, res_len1); + write_float_string (dtp, result1, flt_str_len1); write_char (dtp, semi_comma); - write_float_string (dtp, result2, res_len2); + write_float_string (dtp, result2, flt_str_len2); write_char (dtp, ')'); dtp->u.p.scale_factor = orig_scale; -- 2.30.2