summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2014-01-25 03:21:39 +0400
committerWerner Koch <wk@gnupg.org>2014-01-27 14:33:33 +0100
commit5c150ece094bf0a504a111ce6c7b72e8d0b0457a (patch)
treee8a5cec45e886448b472eaa9d45990d75ed19c9c
parent6d87e6abdfb7552323a95401f14e6367398a3e5a (diff)
downloadlibgcrypt-5c150ece094bf0a504a111ce6c7b72e8d0b0457a.tar.gz
Fix most of memory leaks in tests code
* 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@gmail.com>
-rw-r--r--tests/basic.c6
-rw-r--r--tests/benchmark.c2
-rw-r--r--tests/keygen.c1
-rw-r--r--tests/mpitests.c1
-rw-r--r--tests/t-mpi-point.c1
-rw-r--r--tests/t-sexp.c1
6 files changed, 10 insertions, 2 deletions
diff --git a/tests/basic.c b/tests/basic.c
index e85e4e17..4474a9de 100644
--- a/tests/basic.c
+++ b/tests/basic.c
@@ -2213,6 +2213,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
@@ -2305,6 +2307,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)
@@ -3496,7 +3500,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 e009c227..5efc083f 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 e8cf7c5b..4aff9c96 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 9d1206e5..d75aca90 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 d60b3f0a..88bb5bdf 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 ec8b280a..4c482776 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);