crc: [test] fix memory leak

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
This commit is contained in:
Pablo de Lara 2023-12-14 23:47:00 +00:00 committed by Tomasz Kantecki
parent 54d1153a61
commit d65d2b5572
4 changed files with 21 additions and 4 deletions

View File

@ -34,6 +34,7 @@
#include <assert.h>
#include "crc.h"
#include "crc_ref.h"
#include "test.h"
#ifndef RANDOMS
# define RANDOMS 20
@ -116,16 +117,21 @@ int main(int argc, char *argv[])
int r = 0;
int i;
int len, tot;
u8 *src_raw, *dst_raw;
u8 *src_raw = NULL, *dst_raw = NULL;
u8 *src, *dst;
printf("Test crc16_t10dif_copy_test:\n");
src_raw = (u8 *) malloc(TEST_LEN);
dst_raw = (u8 *) malloc(TEST_LEN);
if (NULL == src_raw || NULL == dst_raw) {
if (NULL == src_raw) {
printf("alloc error: Fail");
return -1;
}
dst_raw = (u8 *) malloc(TEST_LEN);
if (NULL == dst_raw) {
printf("alloc error: Fail");
aligned_free(src_raw);
return -1;
}
src = src_raw;
dst = dst_raw;
@ -179,5 +185,9 @@ int main(int argc, char *argv[])
#endif
printf("Test done: %s\n", r ? "Fail" : "Pass");
free(src_raw);
free(dst_raw);
return r;
}

View File

@ -60,7 +60,7 @@ int main(int argc, char *argv[])
int fail = 0;
u32 r = 0;
int i, s;
void *buf_raw;
void *buf_raw = NULL;
unsigned char *buf;
printf("Test crc16_t10dif_test ");
@ -191,5 +191,8 @@ int main(int argc, char *argv[])
if (fail)
printf("\nFailed %d tests\n", fail);
if (buf)
aligned_free(buf_raw);
return fail;
}

View File

@ -133,6 +133,8 @@ int main(int argc, char *argv[])
printf("CRC32 Tests all done: %s\n", fail ? "Fail" : "Pass");
aligned_free(buf_alloc);
return fail;
}

View File

@ -129,6 +129,8 @@ int main(int argc, char *argv[])
printf("CRC64 Tests all done: %s\n", fail ? "Fail" : "Pass");
aligned_free(buf_alloc);
return fail;
}