From 4c63ec3fce5c3c1460e4f5e9acdcc69074ad8bd3 Mon Sep 17 00:00:00 2001 From: John Bland Date: Tue, 26 Sep 2023 14:29:13 -0400 Subject: [PATCH] fix memory leaks --- src/internal.c | 5 +++++ src/tls.c | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/internal.c b/src/internal.c index 01e9de704..b8336af71 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7993,6 +7993,11 @@ void SSL_ResourceFree(WOLFSSL* ssl) } FreeSuites(ssl); FreeHandshakeHashes(ssl); +#ifdef HAVE_ECH + /* try to free the ech hashes in case we errored out */ + ssl->hsHashes = ssl->hsHashesEch; + FreeHandshakeHashes(ssl); +#endif XFREE(ssl->buffers.domainName.buffer, ssl->heap, DYNAMIC_TYPE_DOMAIN); /* clear keys struct after session */ diff --git a/src/tls.c b/src/tls.c index 2d4f1b93a..3edae684e 100644 --- a/src/tls.c +++ b/src/tls.c @@ -11808,6 +11808,9 @@ static int TLSX_ECH_Parse(WOLFSSL* ssl, const byte* readBuf, word16 size, /* set the ech payload of the copy to zeros */ XMEMSET(aadCopy + (readBuf_p - ech->aad), 0, ech->innerClientHelloLen + AES_BLOCK_SIZE); + /* free the old ech in case this is our second client hello */ + if (ech->innerClientHello != NULL) + XFREE(ech->innerClientHello, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER); /* allocate the inner payload buffer */ ech->innerClientHello = (byte*)XMALLOC(ech->innerClientHelloLen + HANDSHAKE_HEADER_SZ,