Fix memory leak when freeing keys

pull/1044/head
Paul Adelsbach 2026-06-18 19:30:40 -07:00 committed by John Safranek
parent 1dc30ed97e
commit 52f6db9fe7
1 changed files with 16 additions and 0 deletions

View File

@ -622,6 +622,22 @@ static void HandshakeInfoFree(HandshakeInfo* hs, void* heap)
#ifndef WOLFSSH_NO_DH
WFREE(hs->primeGroup, heap, DYNTYPE_MPINT);
WFREE(hs->generator, heap, DYNTYPE_MPINT);
if (hs->useDh) {
wc_FreeDhKey(&hs->privKey.dh);
}
#endif
#ifndef WOLFSSH_NO_ECDH
/* privKey is a union; the Curve25519+ML-KEM case also sets
* useEccMlKem but generates a curve25519 key, so free it below. */
if (hs->useEcc || (hs->useEccMlKem && !hs->useCurve25519MlKem)) {
wc_ecc_free(&hs->privKey.ecc);
}
#endif
#if !defined(WOLFSSH_NO_CURVE25519_SHA256) || \
!defined(WOLFSSH_NO_CURVE25519_MLKEM768_SHA256)
if (hs->useCurve25519 || hs->useCurve25519MlKem) {
wc_curve25519_free(&hs->privKey.curve25519);
}
#endif
if (hs->kexHashId != WC_HASH_TYPE_NONE) {
wc_HashFree(&hs->kexHash, (enum wc_HashType)hs->kexHashId);