Skip to content

Commit 1866853

Browse files
authored
Merge pull request #9883 from JacobBarthelmeh/f279
Fix to free RNG with SRP function in failure case
2 parents ad3ad56 + 54816e8 commit 1866853

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

wolfcrypt/src/srp.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,16 @@ int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size)
543543
static int wc_SrpGenPrivate(Srp* srp, byte* priv, word32 size)
544544
{
545545
WC_RNG rng;
546-
int r = wc_InitRng_ex(&rng, srp->heap, INVALID_DEVID);
547-
548-
if (!r) r = wc_RNG_GenerateBlock(&rng, priv, size);
549-
if (!r) r = wc_SrpSetPrivate(srp, priv, size);
550-
if (!r) wc_FreeRng(&rng);
546+
int r;
551547

548+
r = wc_InitRng_ex(&rng, srp->heap, INVALID_DEVID);
549+
if (r == 0) {
550+
r = wc_RNG_GenerateBlock(&rng, priv, size);
551+
if (r == 0) {
552+
r = wc_SrpSetPrivate(srp, priv, size);
553+
}
554+
wc_FreeRng(&rng);
555+
}
552556
return r;
553557
}
554558

0 commit comments

Comments
 (0)