aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJanus Weil <janus@gcc.gnu.org>2011-05-18 20:51:08 +0200
committerJanus Weil <janus@gcc.gnu.org>2011-05-18 20:51:08 +0200
commit8199eea14f1ab32d805cc4be98ecfb5424a78671 (patch)
treead7ecddf948f98d5f55288d89f5c8fa76fad0fd2 /gcc
parentb5ee67520324dd4185e13374613b55970cfe5169 (diff)
downloadgcc-8199eea14f1ab32d805cc4be98ecfb5424a78671.zip
gcc-8199eea14f1ab32d805cc4be98ecfb5424a78671.tar.gz
gcc-8199eea14f1ab32d805cc4be98ecfb5424a78671.tar.bz2
re PR fortran/48700 (memory leak with MOVE_ALLOC)
2011-05-18 Janus Weil <janus@gcc.gnu.org> PR fortran/48700 * trans-intrinsic.c (gfc_conv_intrinsic_move_alloc): Deallocate 'TO' argument to avoid memory leaks. 2011-05-18 Janus Weil <janus@gcc.gnu.org> PR fortran/48700 * gfortran.dg/move_alloc_4.f90: New. From-SVN: r173874
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/trans-intrinsic.c15
-rw-r--r--gcc/testsuite/gfortran.dg/move_alloc_4.f9022
2 files changed, 36 insertions, 1 deletions
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index fa5d3cf..3cfaa0d 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -6958,15 +6958,28 @@ gfc_conv_intrinsic_move_alloc (gfc_code *code)
if (code->ext.actual->expr->rank == 0)
{
/* Scalar arguments: Generate pointer assignments. */
- gfc_expr *from, *to;
+ gfc_expr *from, *to, *deal;
stmtblock_t block;
tree tmp;
+ gfc_se se;
from = code->ext.actual->expr;
to = code->ext.actual->next->expr;
gfc_start_block (&block);
+ /* Deallocate 'TO' argument. */
+ gfc_init_se (&se, NULL);
+ se.want_pointer = 1;
+ deal = gfc_copy_expr (to);
+ if (deal->ts.type == BT_CLASS)
+ gfc_add_data_component (deal);
+ gfc_conv_expr (&se, deal);
+ tmp = gfc_deallocate_scalar_with_status (se.expr, NULL, true,
+ deal, deal->ts);
+ gfc_add_expr_to_block (&block, tmp);
+ gfc_free_expr (deal);
+
if (to->ts.type == BT_CLASS)
tmp = gfc_trans_class_assign (to, from, EXEC_POINTER_ASSIGN);
else
diff --git a/gcc/testsuite/gfortran.dg/move_alloc_4.f90 b/gcc/testsuite/gfortran.dg/move_alloc_4.f90
new file mode 100644
index 0000000..1f5deed
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/move_alloc_4.f90
@@ -0,0 +1,22 @@
+! { dg-do run }
+! { dg-options "-fdump-tree-original" }
+!
+! PR 48700: memory leak with MOVE_ALLOC
+!
+! Contributed by Salvatore Filippone <sfilippone@uniroma2.it>
+
+program testmv3
+ type bar
+ integer, allocatable :: ia(:), ja(:)
+ end type
+
+ type(bar), allocatable :: sm,sm2
+
+ allocate(sm)
+ allocate(sm%ia(10),sm%ja(10))
+
+ call move_alloc(sm2,sm)
+
+end program testmv3
+
+! { dg-final { scan-tree-dump-times "__builtin_free" 9 "original" } }