| 1 | /* Copyright (C) 2009 Pierre-Marc Fournier |
| 2 | * |
| 3 | * SPDX-License-Identifier: LGPL-2.1-only |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | /* This program is used to test malloc instrumentation with libustinstr-malloc. |
| 8 | */ |
| 9 | |
| 10 | #include <string.h> |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | #define N_ITER 1000 |
| 14 | |
| 15 | int main(int argc, char **argv) |
| 16 | { |
| 17 | int i; |
| 18 | const char teststr[] = "Hello World! 1234567890abc"; |
| 19 | void *ptrs[N_ITER]; |
| 20 | |
| 21 | for (i = 0; i < N_ITER; i++) { |
| 22 | ptrs[i] = malloc(i+1000); |
| 23 | if (!ptrs[i]) { |
| 24 | exit(EXIT_FAILURE); |
| 25 | } |
| 26 | |
| 27 | memcpy(ptrs[i], teststr, sizeof(teststr)); |
| 28 | |
| 29 | if (i % 2 == 0) { |
| 30 | free(ptrs[i]); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | for (i = 0; i < N_ITER; i++) { |
| 35 | if (i % 2 == 1) |
| 36 | free(ptrs[i]); |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |