[PATCH] Fix memleaks in (self)tests.
Peter Wu
peter at lekensteyn.nl
Wed Mar 23 18:21:53 CET 2016
* cipher/dsa.c: release memory for MPI and sexp structures.
* cipher/ecc.c: release memory for sexp structure.
* tests/keygen.c: Likewise.
--
These leaks broke the mpitests, basic and keygen tests when running
under AddressSanitizer.
Signed-off-by: Peter Wu <peter at lekensteyn.nl>
---
cipher/dsa.c | 7 +++++++
cipher/ecc.c | 1 +
tests/keygen.c | 3 +++
3 files changed, 11 insertions(+)
diff --git a/cipher/dsa.c b/cipher/dsa.c
index 909a8ca..40fdcfe 100644
--- a/cipher/dsa.c
+++ b/cipher/dsa.c
@@ -1254,6 +1254,7 @@ selftest_sign (gcry_sexp_t pkey, gcry_sexp_t skey)
calculated_r = _gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
if (!calculated_r)
goto leave;
+ sexp_release (l2);
l2 = _gcry_sexp_find_token (l1, "s", 0);
if (!l2)
@@ -1289,6 +1290,12 @@ selftest_sign (gcry_sexp_t pkey, gcry_sexp_t skey)
leave:
+ _gcry_mpi_release (calculated_s);
+ _gcry_mpi_release (calculated_r);
+ _gcry_mpi_release (s);
+ _gcry_mpi_release (r);
+ sexp_release (l2);
+ sexp_release (l1);
sexp_release (sig);
sexp_release (data_bad);
sexp_release (data);
diff --git a/cipher/ecc.c b/cipher/ecc.c
index 5b03530..f233f78 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -2045,6 +2045,7 @@ selftest_sign (gcry_sexp_t pkey, gcry_sexp_t skey)
calculated_r = _gcry_sexp_nth_mpi (l2, 1, GCRYMPI_FMT_USG);
if (!calculated_r)
goto leave;
+ sexp_release (l2);
l2 = _gcry_sexp_find_token (l1, "s", 0);
if (!l2)
diff --git a/tests/keygen.c b/tests/keygen.c
index ebb708b..a6795bb 100644
--- a/tests/keygen.c
+++ b/tests/keygen.c
@@ -219,6 +219,8 @@ check_rsa_keys (void)
" ))", 0, 1);
if (rc)
die ("error creating S-expression: %s\n", gpg_strerror (rc));
+ gcry_sexp_release (key);
+
rc = gcry_pk_genkey (&key, keyparm);
gcry_sexp_release (keyparm);
if (rc && !in_fips_mode)
@@ -560,6 +562,7 @@ check_ecc_keys (void)
if (verbose && rc && in_fips_mode)
show ("... correctly rejected key creation in FIPS mode (%s)\n",
gpg_strerror (rc));
+ gcry_sexp_release (key);
if (verbose)
show ("creating ECC key using curve NIST P-384 for ECDSA\n");
--
2.7.4
More information about the Gcrypt-devel
mailing list