[PATCH] Add missing free calls for wolfSSL structs

Juliusz Sosinowicz juliusz at wolfssl.com
Thu Apr 28 05:16:36 PDT 2022


In some configurations the `wc_Init*` functions may either allocate memory or other system resources. These resources need to be freed.

Co-authored-by: JacobBarthelmeh <jacob at wolfssl.com>
Signed-off-by: Juliusz Sosinowicz <juliusz at wolfssl.com>
---
 src/crypto/crypto_wolfssl.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/crypto/crypto_wolfssl.c b/src/crypto/crypto_wolfssl.c
index 6014cfb940..32d75ba6dc 100644
--- a/src/crypto/crypto_wolfssl.c
+++ b/src/crypto/crypto_wolfssl.c
@@ -92,6 +92,7 @@ int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
 		wc_ShaUpdate(&sha, addr[i], len[i]);
 
 	wc_ShaFinal(&sha, mac);
+	wc_ShaFree(&sha);
 
 	return 0;
 }
@@ -113,6 +114,7 @@ int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
 		wc_Sha256Update(&sha256, addr[i], len[i]);
 
 	wc_Sha256Final(&sha256, mac);
+	wc_Sha256Free(&sha256);
 
 	return 0;
 }
@@ -135,6 +137,7 @@ int sha384_vector(size_t num_elem, const u8 *addr[], const size_t *len,
 		wc_Sha384Update(&sha384, addr[i], len[i]);
 
 	wc_Sha384Final(&sha384, mac);
+	wc_Sha384Free(&sha384);
 
 	return 0;
 }
@@ -157,6 +160,7 @@ int sha512_vector(size_t num_elem, const u8 *addr[], const size_t *len,
 		wc_Sha512Update(&sha512, addr[i], len[i]);
 
 	wc_Sha512Final(&sha512, mac);
+	wc_Sha512Free(&sha512);
 
 	return 0;
 }
@@ -183,6 +187,8 @@ static int wolfssl_hmac_vector(int type, const u8 *key,
 			return -1;
 	if (wc_HmacFinal(&hmac, mac) != 0)
 		return -1;
+	wc_HmacFree(&hmac);
+
 	return 0;
 }
 
-- 
2.25.1




More information about the Hostap mailing list