From aeb5a8d9580c9e5ac5bc4eeb9b57f64508295f57 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sat, 17 Nov 2018 15:18:27 -0300 Subject: [PATCH] fix memory leak --- test/test.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/test/test.c b/test/test.c index bf8368e..f36e428 100644 --- a/test/test.c +++ b/test/test.c @@ -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);