chiark / gitweb /
rsa: Prepare rsa_loadpub_core for failure.
[secnet.git] / rsa.c
diff --git a/rsa.c b/rsa.c
index 44b9b818b7e5a28440d7d78f83486e4a2b3bb23f..e7f28b91bcb64db95a4f40acb31a57bb4de0b678 100644 (file)
--- a/rsa.c
+++ b/rsa.c
@@ -96,6 +96,9 @@ struct rsapriv {
 #define RSAPUB_LOADCORE_PASSBN(ix,en,what) \
     en##s, en##_loc,
 
+#define RSAPUB_INIT_ST_BN( ix,en,what) mpz_init (&st->en);
+#define RSAPUB_CLEAR_ST_BN(ix,en,what) mpz_clear(&st->en);
+
 struct rsapub {
     closure_t cl;
     struct sigpubkey_if ops;
@@ -336,6 +339,7 @@ static struct rsapub *rsa_loadpub_core(RSAPUB_BNS(RSAPUB_LOADCORE_DEFBN)
     st->ops.hash=0;
     st->ops.dispose=rsapub_dispose;
     st->loc=overall_loc;
+    RSAPUB_BNS(RSAPUB_INIT_ST_BN)
 
 #define RSAPUB_LOADCORE_GETBN(ix,en,what)                              \
     if (mpz_init_set_str(&st->en,en##s,10)!=0) {                       \
@@ -349,6 +353,10 @@ static struct rsapub *rsa_loadpub_core(RSAPUB_BNS(RSAPUB_LOADCORE_DEFBN)
     RSAPUB_BNS(RSAPUB_LOADCORE_GETBN)
 
     return st;
+
+ error_out:
+    rsapub_dispose(st);
+    return 0;
 }
 
 static list_t *rsapub_apply(closure_t *self, struct cloc loc, dict_t *context,