summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilippe Reynes <philippe.reynes@softathome.com>2020-02-06 17:12:59 +0100
committerTom Rini <trini@konsulko.com>2020-02-13 10:10:50 -0500
commit58b209cf6060db60375a2ca9fb21febfae3b8f31 (patch)
tree2fe511c43fb912e3fd0074750491c16ff5e04e48 /test
parent58fc2b54f5b9102d593f3b98c370b6cbaeb97ac2 (diff)
test: aes: fix memleak
In the first version, the result of malloc is checked with ut_assertnonnull. But on a fail, this macro exit the function, so previously malloc are not freed. So to avoid a memleak, we don't use ut_assertnonnull, but simply check the return of malloc. If one has failed, we freed all the allocated memory and quit the function. Reported-by: Coverity (CID: 284403) Reported-by: Coverity (CID: 284404) Reported-by: Coverity (CID: 284405) Reported-by: Coverity (CID: 284406) Reported-by: Coverity (CID: 284407) Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Diffstat (limited to 'test')
-rw-r--r--test/lib/test_aes.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/test/lib/test_aes.c b/test/lib/test_aes.c
index b7b4b775df..fb8a0b17ba 100644
--- a/test/lib/test_aes.c
+++ b/test/lib/test_aes.c
@@ -88,17 +88,17 @@ static int _lib_test_aes_run(struct unit_test_state *uts, int key_len,
/* Allocate all the buffer */
key = malloc(key_len);
- ut_assertnonnull(key);
key_exp = malloc(key_exp_len);
- ut_assertnonnull(key_exp);
iv = malloc(AES_BLOCK_LENGTH);
- ut_assertnonnull(iv);
nocipher = malloc(num_block * AES_BLOCK_LENGTH);
- ut_assertnonnull(nocipher);
ciphered = malloc((num_block + 1) * AES_BLOCK_LENGTH);
- ut_assertnonnull(ciphered);
uncipher = malloc((num_block + 1) * AES_BLOCK_LENGTH);
- ut_assertnonnull(uncipher);
+
+ if (!key || !key_exp || !iv || !nocipher || !ciphered || !uncipher) {
+ printf("%s: can't allocate memory\n", __func__);
+ ret = -1;
+ goto out;
+ }
/* Initialize all buffer */
rand_buf(key, key_len);
@@ -127,6 +127,7 @@ static int _lib_test_aes_run(struct unit_test_state *uts, int key_len,
ret = -1;
};
+ out:
/* Free all the data */
free(key);
free(key_exp);