While looking at code related to PR fortran/78618, I 
noticed a memory leak.  The following patch plus the
leak.

2016-12-02  Steven G. Kargl  <ka...@gcc.gnu.org>

        * simplify.c (gfc_convert_char_constant): Free result on error.

Index: simplify.c
===================================================================
--- simplify.c  (revision 243203)
+++ simplify.c  (working copy)
@@ -7152,6 +7152,7 @@ gfc_convert_char_constant (gfc_expr *e, 
                       "into character kind %d",
                       gfc_print_wide_char (result->value.character.string[i]),
                       &e->where, kind);
+           gfc_free_expr (result);
            return &gfc_bad_expr;
          }
 
Without the patch, valgrind finds

==4426== LEAK SUMMARY:
==4426==    definitely lost: 192 bytes in 1 blocks
==4426==    indirectly lost: 8 bytes in 1 blocks
==4426==      possibly lost: 6,256 bytes in 21 blocks
==4426==    still reachable: 817,676 bytes in 2,185 blocks
==4426==         suppressed: 0 bytes in 0 blocks

With the patch, she shows

==15883== LEAK SUMMARY:
==15883==    definitely lost: 0 bytes in 0 blocks
==15883==    indirectly lost: 0 bytes in 0 blocks
==15883==      possibly lost: 6,256 bytes in 21 blocks
==15883==    still reachable: 817,676 bytes in 2,185 blocks
==15883==         suppressed: 0 bytes in 0 blocks

-- 
Steve

Reply via email to