cipher: fix memory leaks

NIIBE Yutaka gniibe at fsij.org
Thu Aug 8 00:57:59 CEST 2013


On 2013-08-06 at 17:35 +0900, NIIBE Yutaka wrote:
> For ECC ("pabgnqd", with no Q, but D), I try following patch.  It
> works, but doesn't look so good.

This is too large, as it includes API changes:

 pubkey.c |  124 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 71 insertions(+), 53 deletions(-)

Instead, following is a makeshift solution, but small and local, and
enough to fix the specific problem.

I'll commit this change.  I think that this is the last one of
my memory leak series.

diff --git a/cipher/pubkey.c b/cipher/pubkey.c
index e867169..f9c2193 100644
--- a/cipher/pubkey.c
+++ b/cipher/pubkey.c
@@ -3339,7 +3339,15 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey)
  leave:
   if (skey)
     {
-      release_mpi_array (skey);
+      if (is_ecc)
+        for (i = 0; i < 7; i++)
+          {
+            if (skey[i])
+              mpi_free (skey[i]);
+            skey[i] = NULL;
+          }
+      else
+        release_mpi_array (skey);
       gcry_free (skey);
     }
 
-- 






More information about the Gcrypt-devel mailing list