Skip to content

Commit d65d2b5

Browse files
pablodelaratkanteck
authored andcommitted
crc: [test] fix memory leak
Signed-off-by: Pablo de Lara <[email protected]>
1 parent 54d1153 commit d65d2b5

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

crc/crc16_t10dif_copy_test.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <assert.h>
3535
#include "crc.h"
3636
#include "crc_ref.h"
37+
#include "test.h"
3738

3839
#ifndef RANDOMS
3940
# define RANDOMS 20
@@ -116,14 +117,19 @@ int main(int argc, char *argv[])
116117
int r = 0;
117118
int i;
118119
int len, tot;
119-
u8 *src_raw, *dst_raw;
120+
u8 *src_raw = NULL, *dst_raw = NULL;
120121
u8 *src, *dst;
121122

122123
printf("Test crc16_t10dif_copy_test:\n");
123124
src_raw = (u8 *) malloc(TEST_LEN);
125+
if (NULL == src_raw) {
126+
printf("alloc error: Fail");
127+
return -1;
128+
}
124129
dst_raw = (u8 *) malloc(TEST_LEN);
125-
if (NULL == src_raw || NULL == dst_raw) {
130+
if (NULL == dst_raw) {
126131
printf("alloc error: Fail");
132+
aligned_free(src_raw);
127133
return -1;
128134
}
129135
src = src_raw;
@@ -179,5 +185,9 @@ int main(int argc, char *argv[])
179185
#endif
180186

181187
printf("Test done: %s\n", r ? "Fail" : "Pass");
188+
189+
free(src_raw);
190+
free(dst_raw);
191+
182192
return r;
183193
}

crc/crc16_t10dif_test.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
6060
int fail = 0;
6161
u32 r = 0;
6262
int i, s;
63-
void *buf_raw;
63+
void *buf_raw = NULL;
6464
unsigned char *buf;
6565

6666
printf("Test crc16_t10dif_test ");
@@ -191,5 +191,8 @@ int main(int argc, char *argv[])
191191
if (fail)
192192
printf("\nFailed %d tests\n", fail);
193193

194+
if (buf)
195+
aligned_free(buf_raw);
196+
194197
return fail;
195198
}

crc/crc32_funcs_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ int main(int argc, char *argv[])
133133

134134
printf("CRC32 Tests all done: %s\n", fail ? "Fail" : "Pass");
135135

136+
aligned_free(buf_alloc);
137+
136138
return fail;
137139
}
138140

crc/crc64_funcs_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ int main(int argc, char *argv[])
129129

130130
printf("CRC64 Tests all done: %s\n", fail ? "Fail" : "Pass");
131131

132+
aligned_free(buf_alloc);
133+
132134
return fail;
133135
}
134136

0 commit comments

Comments
 (0)