diff mbox

[Committed,fortran] Plug memory leak.

Message ID 20161202221120.GA15928@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Dec. 2, 2016, 10:11 p.m. UTC
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  <kargl@gcc.gnu.org>

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

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
diff mbox

Patch

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;
 	  }