summaryrefslogtreecommitdiff
path: root/cipher/rsa.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2006-06-21 09:19:13 +0000
committerWerner Koch <wk@gnupg.org>2006-06-21 09:19:13 +0000
commiteb9ebf3b7f1bceec03fa8785aa1138be29a73ff2 (patch)
tree9b1c180778f8e8c4cd9d7ee27406edc7a8c0beef /cipher/rsa.c
parent54c8861ff110789261ee546cc76e19c3199c2120 (diff)
downloadlibgcrypt-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.c21
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;
}