[PATCH 3/7] test: self: digest: don't leak digest buffers

Ahmad Fatoum a.fatoum at pengutronix.de
Fri May 17 00:48:20 PDT 2024


The selftest leaks memory by letting the pointers go out of scope.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/self/digest.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/test/self/digest.c b/test/self/digest.c
index 4cda5b09637b..32815c85ba70 100644
--- a/test/self/digest.c
+++ b/test/self/digest.c
@@ -47,7 +47,7 @@ static void __test_digest(bool option,
 			  const char *algo, struct digest_test_case *t,
 			  const char *func, int line)
 {
-	unsigned char *output, *digest;
+	unsigned char *output = NULL, *digest = NULL;
 	struct digest *d;
 	int hash_len, digest_len;
 	u64 start;
@@ -103,8 +103,14 @@ static void __test_digest(bool option,
 		goto fail;
 	}
 
+	digest_free(d);
+	free(digest);
+	free(output);
 	return;
 fail:
+	digest_free(d);
+	free(digest);
+	free(output);
 	failed_tests++;
 }
 
-- 
2.39.2




More information about the barebox mailing list