[1/3] go: Fix memory leak in Integer_expression

Message ID 20230402150515.40826-2-rep.dot.nop@gmail.com
State Accepted
Headers
Series [1/3] go: Fix memory leak in Integer_expression |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Bernhard Reutner-Fischer April 2, 2023, 3:05 p.m. UTC
  From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

Cc: Ian Lance Taylor <ian@airs.com>

gcc/go/ChangeLog:

	* gofrontend/expressions.cc (Integer_expression::do_import): Fix
	memory leak.
---
 gcc/go/gofrontend/expressions.cc | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 4ac55af7433..93f5d5dc52b 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -2728,6 +2728,7 @@  Integer_expression::do_import(Import_expression* imp, Location loc)
 	    {
 	      go_error_at(imp->location(), "bad number in import data: %qs",
 			  real_str.c_str());
+	      mpfr_clear (real);
 	      return Expression::make_error(loc);
 	    }
 	}
@@ -2743,6 +2744,8 @@  Integer_expression::do_import(Import_expression* imp, Location loc)
 	{
 	  go_error_at(imp->location(), "bad number in import data: %qs",
 		      imag_str.c_str());
+	  mpfr_clear (imag);
+	  mpfr_clear (real);
 	  return Expression::make_error(loc);
 	}
       mpc_t cval;
@@ -2766,6 +2769,7 @@  Integer_expression::do_import(Import_expression* imp, Location loc)
 	{
 	  go_error_at(imp->location(), "bad number in import data: %qs",
 		      num.c_str());
+	  mpz_clear (val);
 	  return Expression::make_error(loc);
 	}
       Expression* ret;
@@ -2783,6 +2787,7 @@  Integer_expression::do_import(Import_expression* imp, Location loc)
 	{
 	  go_error_at(imp->location(), "bad number in import data: %qs",
 		      num.c_str());
+	  mpfr_clear (val);
 	  return Expression::make_error(loc);
 	}
       Expression* ret = Expression::make_float(&val, NULL, loc);