diff options
author | Werner Koch <wk@gnupg.org> | 2006-06-21 09:19:13 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2006-06-21 09:19:13 +0000 |
commit | eb9ebf3b7f1bceec03fa8785aa1138be29a73ff2 (patch) | |
tree | 9b1c180778f8e8c4cd9d7ee27406edc7a8c0beef /cipher/rsa.c | |
parent | 54c8861ff110789261ee546cc76e19c3199c2120 (diff) | |
download | libgcrypt-eb9ebf3b7f1bceec03fa8785aa1138be29a73ff2.tar.gz |
Changed xmalloc style calls to proper malloc calls with error returns at
many (but not all) places.
Diffstat (limited to 'cipher/rsa.c')
-rw-r--r-- | cipher/rsa.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/cipher/rsa.c b/cipher/rsa.c index 9cceba21..18fda93e 100644 --- a/cipher/rsa.c +++ b/cipher/rsa.c @@ -28,6 +28,8 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <errno.h> + #include "g10lib.h" #include "mpi.h" #include "cipher.h" @@ -440,6 +442,8 @@ _gcry_rsa_generate (int algo, unsigned int nbits, unsigned long use_e, gcry_mpi_t *skey, gcry_mpi_t **retfactors) { RSA_secret_key sk; + gpg_err_code_t rc; + int i; generate (&sk, nbits, use_e); skey[0] = sk.n; @@ -449,10 +453,21 @@ _gcry_rsa_generate (int algo, unsigned int nbits, unsigned long use_e, skey[4] = sk.q; skey[5] = sk.u; - /* make an empty list of factors */ - *retfactors = gcry_xcalloc( 1, sizeof **retfactors ); + /* Make an empty list of factors. */ + *retfactors = gcry_calloc ( 1, sizeof **retfactors ); + if (!*retfactors) + { + rc = gpg_err_code_from_errno (errno); + for (i=0; i <= 5; i++) + { + gcry_mpi_release (skey[i]); + skey[i] = NULL; + } + } + else + rc = 0; - return GPG_ERR_NO_ERROR; + return rc; } |