[committed] Fortran: fix memory leak with real to integer conversion warning

Message ID trinity-a0a55c0d-964c-4a07-bc72-e3fe5e733cb0-1677349043450@3c-app-gmx-bap72
State Repeat Merge
Headers
Series [committed] Fortran: fix memory leak with real to integer conversion warning |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Harald Anlauf Feb. 25, 2023, 6:17 p.m. UTC
  Dear all,

while checking f951 for memory leaks on testcases that appeared
relevant during work on pr108924, I found that the conversion
warning triggered by do_subscript_6.f90 uses a code path that
forgot to mpfr_clear a used variable.

The attached obvious patch fixes this - verified by valgrind.

Pushed to mainline as r13-6344-g03c60e525bea13 .

Thanks,
Harald
  

Patch

From 03c60e525bea13c15edd2f64cd582f168fe80bfb Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Sat, 25 Feb 2023 19:05:38 +0100
Subject: [PATCH] Fortran: fix memory leak with real to integer conversion
 warning

gcc/fortran/ChangeLog:

	* arith.cc (gfc_real2int): Clear mpfr variable after use.
---
 gcc/fortran/arith.cc | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index d0d1c0b03d2..37aeaf1b186 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -2257,6 +2257,7 @@  gfc_real2int (gfc_expr *src, int kind)
 			   gfc_typename (&result->ts), &src->where);
 	  did_warn = true;
 	}
+      mpfr_clear (f);
     }
   if (!did_warn && warn_conversion_extra)
     {
--
2.35.3