Skip to content

Commit 52f6db9

Browse files
padelsbachejohnstown
authored andcommitted
Fix memory leak when freeing keys
1 parent 1dc30ed commit 52f6db9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/internal.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ static void HandshakeInfoFree(HandshakeInfo* hs, void* heap)
622622
#ifndef WOLFSSH_NO_DH
623623
WFREE(hs->primeGroup, heap, DYNTYPE_MPINT);
624624
WFREE(hs->generator, heap, DYNTYPE_MPINT);
625+
if (hs->useDh) {
626+
wc_FreeDhKey(&hs->privKey.dh);
627+
}
628+
#endif
629+
#ifndef WOLFSSH_NO_ECDH
630+
/* privKey is a union; the Curve25519+ML-KEM case also sets
631+
* useEccMlKem but generates a curve25519 key, so free it below. */
632+
if (hs->useEcc || (hs->useEccMlKem && !hs->useCurve25519MlKem)) {
633+
wc_ecc_free(&hs->privKey.ecc);
634+
}
635+
#endif
636+
#if !defined(WOLFSSH_NO_CURVE25519_SHA256) || \
637+
!defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
638+
if (hs->useCurve25519 || hs->useCurve25519MlKem) {
639+
wc_curve25519_free(&hs->privKey.curve25519);
640+
}
625641
#endif
626642
if (hs->kexHashId != WC_HASH_TYPE_NONE) {
627643
wc_HashFree(&hs->kexHash, (enum wc_HashType)hs->kexHashId);

0 commit comments

Comments
 (0)