From 6a40535166a728bc465acd5a19d98a9c992b5241 Mon Sep 17 00:00:00 2001
From: Paul Zimmermann <Paul.Zimmermann@inria.fr>
Date: Fri, 21 Jun 2024 08:31:45 +0200
Subject: [PATCH] fixed memory leak detected by valgrind

("make longcheck" with --enable-valgrind-tests)
---
 README.dev |  5 +++--
 ecm.c      | 11 ++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/README.dev b/README.dev
index 13bc6b21..1318d4eb 100644
--- a/README.dev
+++ b/README.dev
@@ -63,8 +63,9 @@ To make a new release:
      Check no compiler warnings remain (with and without assertions),
         if possible with different compilers (gcc, clang, llvm-gcc, ...)
      Check "make longcheck" works with --enable-valgrind-tests.
-     Check that configure works outside the source directory.
-     Check the default tuning files */params.h (and */*/params.h, see the main
+     Check that configure works outside the source directory
+        (from the tarball).
+     Check the default tuning files */params.h (see the main
      file ecm-params.h) on different platforms with "make ecm-params"
      Compare the efficiency wrt the previous release with "./ecm 1e6 < c270"
      and "./ecmbench ./ecm".
diff --git a/ecm.c b/ecm.c
index 7411efd5..9e7b4bc6 100644
--- a/ecm.c
+++ b/ecm.c
@@ -2253,13 +2253,14 @@ ecm (mpz_t f, mpz_t x, mpz_t y, int param, mpz_t sigma, mpz_t n, mpz_t go,
                                 stop_asap, chkfilename);
 #ifdef HAVE_ADDLAWS
 	    else{
-		ell_point_init(PE, E, modulus);
-		mpres_set(PE->x, P.x, modulus);
-		mpres_set(PE->y, P.y, modulus);
+		ell_point_init (PE, E, modulus);
+		mpres_set (PE->x, P.x, modulus);
+		mpres_set (PE->y, P.y, modulus);
 		youpi = ecm_stage1_W (f, E, PE, modulus, B1, B1done, batch_s,
 				      go, stop_asap, chkfilename);
-		mpres_set(P.x, PE->x, modulus);
-		mpres_set(P.y, PE->y, modulus);
+		mpres_set (P.x, PE->x, modulus);
+		mpres_set (P.y, PE->y, modulus);
+                ell_point_clear (PE, E, modulus);
 	    }
 #endif
 	}
-- 
GitLab