Skip to content

Commit 71575ae

Browse files
pablodelaratkanteck
authored andcommitted
raid: [example] fix memory leak in CRC64 example
Signed-off-by: Pablo de Lara <[email protected]>
1 parent 9ee34ec commit 71575ae

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

raid/xor_example.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,22 @@
2929
#include <stdio.h>
3030
#include <stdlib.h>
3131
#include "raid.h"
32+
#include "test.h"
3233

3334
#define TEST_SOURCES 16
3435
#define TEST_LEN 16*1024
3536

3637
int main(int argc, char *argv[])
3738
{
38-
int i, j, should_pass, should_fail;
39-
void *buffs[TEST_SOURCES + 1];
39+
int i, j, should_pass, should_fail, ret = 0;
40+
void *buffs[TEST_SOURCES + 1] = { NULL };
4041

4142
printf("XOR example\n");
4243
for (i = 0; i < TEST_SOURCES + 1; i++) {
4344
void *buf;
4445
if (posix_memalign(&buf, 32, TEST_LEN)) {
4546
printf("alloc error: Fail");
46-
return 1;
47+
goto exit;
4748
}
4849
buffs[i] = buf;
4950
}
@@ -59,11 +60,21 @@ int main(int argc, char *argv[])
5960
printf("Check parity: ");
6061
should_pass = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs);
6162
printf("%s\n", should_pass == 0 ? "Pass" : "Fail");
63+
if (should_pass != 0) {
64+
ret = -1;
65+
goto exit;
66+
}
6267

6368
printf("Find corruption: ");
6469
((char *)buffs[TEST_SOURCES / 2])[TEST_LEN / 2] ^= 1; // flip one bit
6570
should_fail = xor_check(TEST_SOURCES + 1, TEST_LEN, buffs); //recheck
6671
printf("%s\n", should_fail != 0 ? "Pass" : "Fail");
6772

68-
return 0;
73+
if (should_fail == 0)
74+
ret = -1;
75+
exit:
76+
for (i = 0; i < TEST_SOURCES + 1; i++)
77+
free(buffs[i]);
78+
79+
return ret;
6980
}

0 commit comments

Comments
 (0)