This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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, fortran] PR29101 - Memory leak in select case with character expression


:ADDPATCH fortran:

This:
FUNCTION tolower(instr) RESULT (outstr)
CHARACTER(len=*), INTENT(in) :: instr
CHARACTER(len=len(instr)) :: outstr
...snip...
SELECT CASE (tolower(input))
CASE ("x"); value = 1
CASE DEFAULT
validate_value = .FALSE.
END SELECT

causes a memory leak because the post block produced by the conversion of the select case expression is never added to the block and, in consequence, the temporary was not freed.

This

2006-09-18 Paul Thomas <pault@gcc.gnu.org>

PR fortran/29101
* trans-stmt.c (gfc_trans_character_select): Add the post block for the expression
to the main block, after the call to select_string.



Index: gcc/fortran/trans-stmt.c =================================================================== *** gcc/fortran/trans-stmt.c (revision 117013) --- gcc/fortran/trans-stmt.c (working copy) *************** gfc_trans_character_select (gfc_code *co *** 1467,1472 **** --- 1467,1474 ---- tmp = build1 (GOTO_EXPR, void_type_node, tmp); gfc_add_expr_to_block (&block, tmp);

+ gfc_add_block_to_block (&block, &se.post);
+
tmp = gfc_finish_block (&body);
gfc_add_expr_to_block (&block, tmp);
tmp = build1_v (LABEL_EXPR, end_label);

fixes it by producing the code:

pstr.6 = (char[1:D.960] *) _gfortran_internal_malloc (D.960);
tolower (pstr.6, D.960, D.958, D.959);
goto _gfortran_select_string ((void *) &jumptable.5, 2, &L.5, pstr.6, D.960);
_gfortran_internal_free ((void *) pstr.6); /* This was absent. */
L.4:;
*value = 1;
goto L.5;
L.3:;
__result_validate_value = 0;
goto L.5;
L.5:;


It regests on FC5/Athlon.

I intend to commit it under the obvious rule.

I have not attempted to write a testcase, although this could be done.

Paul



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