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]

Re: [Patch, fortran] PR29101 - Memory leak in select case with character expression


Steven,

> I think you need to assign the result of the character  select to a
> temporary, then free, then jump.  I.e. something like this:

I think that I took the stupid pills somewhere in the last 48 hours. I was
having a very hard time seeing the obvious!

This:

Index: gcc/fortran/trans-stmt.c
===================================================================
*** gcc/fortran/trans-stmt.c    (révision 116697)
--- gcc/fortran/trans-stmt.c    (copie de travail)
*************** static tree
*** 1307,1312 ****
--- 1307,1313 ----
  gfc_trans_character_select (gfc_code *code)
  {
    tree init, node, end_label, tmp, type, args, *labels;
+   tree selected_case;
    stmtblock_t block, body;
    gfc_case *cp, *d;
    gfc_code *c;
*************** gfc_trans_character_select (gfc_code *co
*** 1464,1471 ****
    gfc_add_block_to_block (&block, &se.pre);

    tmp = build_function_call_expr (gfor_fndecl_select_string, args);
!   tmp = build1 (GOTO_EXPR, void_type_node, tmp);
    gfc_add_expr_to_block (&block, tmp);

    tmp = gfc_finish_block (&body);
    gfc_add_expr_to_block (&block, tmp);
--- 1465,1478 ----
    gfc_add_block_to_block (&block, &se.pre);

    tmp = build_function_call_expr (gfor_fndecl_select_string, args);
!   selected_case = gfc_create_var (TREE_TYPE (tmp), NULL);
!   gfc_add_modify_expr (&block, selected_case, tmp);
!
!   gfc_add_block_to_block (&block, &se.post);
!
!   tmp = build1 (GOTO_EXPR, void_type_node, selected_case);
    gfc_add_expr_to_block (&block, tmp);
+

    tmp = gfc_finish_block (&body);
    gfc_add_expr_to_block (&block, tmp);


does this

    pstr.6 = (char[1:D.960] *) _gfortran_internal_malloc (D.960);
    tolower (pstr.6, D.960, D.958, D.959);
    D.963 = _gfortran_select_string ((void *) &jumptable.5, 2, &L.5, pstr.6, D.960);
    _gfortran_internal_free ((void *) pstr.6);
    goto D.963;

Thanks, Steven.

Paul


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