Browse Source

fix memory leak

tags/1.0.0
Chris Cromer 10 months ago
parent
commit
aeb5a8d958
Signed by: Chris Cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
1 changed files with 4 additions and 9 deletions
  1. 4
    9
      test/test.c

+ 4
- 9
test/test.c View File

@@ -221,22 +221,16 @@ int main(int argc, char **argv) {

// Test bitonic sort with 2^n
pass = 1;
int *bitonic_test_case = malloc(sizeof(int) * n2);
if (bitonic_test_case == NULL) {
fprintf(stderr, "Error: Out of heap space!\n");
exit(1);
}
int *bitonic_test_array = malloc(sizeof(int) * n2);
if (bitonic_test_array == NULL) {
fprintf(stderr, "Error: Out of heap space!\n");
exit(1);
}
for (i = 0; i < n; i++) {
bitonic_test_case[i] = gen_rand(-1000000, 1000000);
for (i = 0; i < n2; i++) {
bitonic_test_array[i] = gen_rand(-1000000, 1000000);
}
memcpy(qarray, bitonic_test_case, sizeof(int) * n2);
memcpy(qarray, bitonic_test_array, sizeof(int) * n2);
qsort(qarray, n2, sizeof(int), compar);
memcpy(bitonic_test_array, bitonic_test_case, sizeof(int) * n2);
fprintf(stdout, "\tbitonic sort 2^n: ");
fflush(stdout);
bitonic_sort(bitonic_test_array, n2);
@@ -252,6 +246,7 @@ int main(int argc, char **argv) {
fprintf(stdout, "pass\n");
passed++;
}
free(bitonic_test_array);

fprintf(stdout, "%d tests passed\n", passed);
fprintf(stdout, "%d tests failed\n", failed);

Loading…
Cancel
Save