summaryrefslogtreecommitdiffhomepage
path: root/bignum.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2017-05-26 21:08:43 +0800
committerMatt Johnston <matt@ucc.asn.au>2017-05-26 21:08:43 +0800
commitc38927da47fa3c96cdcc7e4c81d9068bf01bf1fb (patch)
treec24afd4e5b05f485e6b42663d5dfdb335dc8117d /bignum.c
parent7ab8f61974601444046888da07f211c44e55e5a5 (diff)
add m_mp_free_multi, be more careful freeing when failing to load keys
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/bignum.c b/bignum.c
index 3758052..b3e2b99 100644
--- a/bignum.c
+++ b/bignum.c
@@ -68,6 +68,22 @@ void m_mp_alloc_init_multi(mp_int **mp, ...)
va_end(args);
}
+void m_mp_free_multi(mp_int **mp, ...)
+{
+ mp_int** cur_arg = mp;
+ va_list args;
+
+ va_start(args, mp); /* init args to next argument from caller */
+ while (cur_arg != NULL) {
+ if (*cur_arg) {
+ mp_clear(*cur_arg);
+ }
+ m_free(*cur_arg);
+ cur_arg = va_arg(args, mp_int**);
+ }
+ va_end(args);
+}
+
void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len) {
if (mp_read_unsigned_bin(mp, (unsigned char*)bytes, len) != MP_OKAY) {