[PATCH 2/2] Fix most of memory leaks in tests code
Dmitry Eremin-Solenikov
dbaryshkov at gmail.com
Sat Jan 25 00:21:39 CET 2014
* tests/basic.c (check_ccm_cipher): Close cipher after use.
* tests/basic.c (check_one_cipher): Correct length of used buffer.
* tests/benchmark.c (cipher_bench): Use xcalloc to make buffer
initialized.
* tests/keygen.c (check_ecc_keys): Release generated key.
* tests/t-mpi-point.c (context_param): Release mpi Q.
* tests/t-sexp.c (check_extract_param): Release extracted number.
--
The only remaining reported memory leak is one expected leak from
mpitests.c.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
---
tests/basic.c | 6 +++++-
tests/benchmark.c | 2 +-
tests/keygen.c | 1 +
tests/mpitests.c | 1 +
tests/t-mpi-point.c | 1 +
tests/t-sexp.c | 1 +
6 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/tests/basic.c b/tests/basic.c
index 8cd638d..bd90d53 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -2450,6 +2450,8 @@ check_ccm_cipher (void)
if (memcmp (buf, tag, taglen) != 0)
fail ("cipher-ccm-large, encrypt mismatch entry\n");
+
+ gcry_cipher_close (hde);
}
#if 0
@@ -2542,6 +2544,8 @@ check_ccm_cipher (void)
if (memcmp (buf, tag, taglen) != 0)
fail ("cipher-ccm-huge, encrypt mismatch entry\n");
+
+ gcry_cipher_close (hde);
}
if (verbose)
@@ -3733,7 +3737,7 @@ check_one_cipher (int algo, int mode, int flags)
return;
/* Pass 2: Key not aligned and data not aligned. */
- memmove (plain+1, plain, 1024);
+ memmove (plain+1, plain, 1040);
if (check_one_cipher_core (algo, mode, flags, key+1, 32, plain+1, 1040,
bufshift, 2+10*bufshift))
return;
diff --git a/tests/benchmark.c b/tests/benchmark.c
index e009c22..5efc083 100644
--- a/tests/benchmark.c
+++ b/tests/benchmark.c
@@ -656,7 +656,7 @@ cipher_bench ( const char *algoname )
}
repetitions *= cipher_repetitions;
- raw_buf = gcry_xmalloc (allocated_buflen+15);
+ raw_buf = gcry_xcalloc (allocated_buflen+15, 1);
buf = (raw_buf
+ ((16 - ((size_t)raw_buf & 0x0f)) % buffer_alignment));
outbuf = raw_outbuf = gcry_xmalloc (allocated_buflen+15);
diff --git a/tests/keygen.c b/tests/keygen.c
index e8cf7c5..4aff9c9 100644
--- a/tests/keygen.c
+++ b/tests/keygen.c
@@ -413,6 +413,7 @@ check_ecc_keys (void)
show_sexp ("ECC key:\n", key);
check_generated_ecc_key (key);
+ gcry_sexp_release (key);
if (verbose)
show ("creating ECC key using curve Ed25519 for ECDSA (nocomp)\n");
diff --git a/tests/mpitests.c b/tests/mpitests.c
index 9d1206e..d75aca9 100644
--- a/tests/mpitests.c
+++ b/tests/mpitests.c
@@ -212,6 +212,7 @@ test_opaque (void)
if (debug)
gcry_log_debugmpi ("mpi", a);
+ gcry_mpi_release (a);
p = gcry_xstrdup ("This is a test buffer");
a = gcry_mpi_set_opaque_copy (NULL, p, 21*8+1);
diff --git a/tests/t-mpi-point.c b/tests/t-mpi-point.c
index d60b3f0..88bb5bd 100644
--- a/tests/t-mpi-point.c
+++ b/tests/t-mpi-point.c
@@ -601,6 +601,7 @@ context_param (void)
if (err)
fail ("setting Q for nistp256 failed: %s\n", gpg_strerror (err));
get_and_cmp_mpi ("q", sample_p256_q, "nistp256(2)", ctx);
+ gcry_mpi_release (q);
/* Get as s-expression. */
err = gcry_pubkey_get_sexp (&sexp, 0, ctx);
diff --git a/tests/t-sexp.c b/tests/t-sexp.c
index ec8b280..4c48277 100644
--- a/tests/t-sexp.c
+++ b/tests/t-sexp.c
@@ -1035,6 +1035,7 @@ check_extract_param (void)
gcry_log_debugmpi (" got", mpis[0]);
}
+ gcry_free (ioarray[0].data);
gcry_mpi_release (mpis[0]);
gcry_sexp_release (sxp);
--
1.8.5.2
More information about the Gcrypt-devel
mailing list