]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix memleak for character,value dummy of bind(c) procedure [PR110360]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 16 Aug 2023 20:00:49 +0000 (22:00 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Wed, 16 Aug 2023 20:00:49 +0000 (22:00 +0200)
Testcase gfortran.dg/bind_c_usage_13.f03 exhibited a memleak in the frontend
occuring when passing a character literal to a character,value dummy of a
bind(c) procedure, due to a missing cleanup in the conversion of the actual
argument expression.  Reduced testcase:

  program p
    interface
       subroutine val_c (c) bind(c)
         use iso_c_binding, only: c_char
         character(len=1,kind=c_char), value :: c
       end subroutine val_c
    end interface
    call val_c ("A")
  end

gcc/fortran/ChangeLog:

PR fortran/110360
* trans-expr.cc (conv_scalar_char_value): Use gfc_replace_expr to
avoid leaking replaced gfc_expr.

gcc/fortran/trans-expr.cc

index 52cd88f5b0079a3c18795e149f5128c78dfece32..6e9e76cd5c9d03c0d3841ffb7462d172266dcd23 100644 (file)
@@ -4044,8 +4044,9 @@ conv_scalar_char_value (gfc_symbol *sym, gfc_se *se, gfc_expr **expr)
       gfc_typespec ts;
       gfc_clear_ts (&ts);
 
-      *expr = gfc_get_int_expr (gfc_default_character_kind, NULL,
-                               (*expr)->value.character.string[0]);
+      gfc_expr *tmp = gfc_get_int_expr (gfc_default_character_kind, NULL,
+                                       (*expr)->value.character.string[0]);
+      gfc_replace_expr (*expr, tmp);
     }
   else if (se != NULL && (*expr)->expr_type == EXPR_VARIABLE)
     {