Browse Source

fix memory leak

Chris Cromer 7 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) {
221 221
 
222 222
 	// Test bitonic sort with 2^n
223 223
 	pass = 1;
224
-	int *bitonic_test_case = malloc(sizeof(int) * n2);
225
-	if (bitonic_test_case == NULL) {
226
-		fprintf(stderr, "Error: Out of heap space!\n");
227
-		exit(1);
228
-	}
229 224
 	int *bitonic_test_array = malloc(sizeof(int) * n2);
230 225
 	if (bitonic_test_array == NULL) {
231 226
 		fprintf(stderr, "Error: Out of heap space!\n");
232 227
 		exit(1);
233 228
 	}
234
-	for (i = 0; i < n; i++) {
235
-		bitonic_test_case[i] = gen_rand(-1000000, 1000000);
229
+	for (i = 0; i < n2; i++) {
230
+		bitonic_test_array[i] = gen_rand(-1000000, 1000000);
236 231
 	}
237
-	memcpy(qarray, bitonic_test_case, sizeof(int) * n2);
232
+	memcpy(qarray, bitonic_test_array, sizeof(int) * n2);
238 233
 	qsort(qarray, n2, sizeof(int), compar);
239
-	memcpy(bitonic_test_array, bitonic_test_case, sizeof(int) * n2);
240 234
 	fprintf(stdout, "\tbitonic sort 2^n: ");
241 235
 	fflush(stdout);
242 236
 	bitonic_sort(bitonic_test_array, n2);
@@ -252,6 +246,7 @@ int main(int argc, char **argv) {
252 246
 		fprintf(stdout, "pass\n");
253 247
 		passed++;
254 248
 	}
249
+	free(bitonic_test_array);
255 250
 
256 251
 	fprintf(stdout, "%d tests passed\n", passed);
257 252
 	fprintf(stdout, "%d tests failed\n", failed);

Loading…
Cancel
Save