| 1 | // RUN: %clangxx_asan %s -o %t |
| 2 | // RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 1 |
| 3 | // RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 4 |
| 4 | |
| 5 | #include <cassert> |
| 6 | #include <sanitizer/allocator_interface.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | void *g; |
| 11 | |
| 12 | int main(int argc, char **argv) { |
| 13 | int s = atoi(nptr: argv[1]) * 1024 * 1024; |
| 14 | int a = __sanitizer_get_heap_size(); |
| 15 | g = malloc(size: s); |
| 16 | int b = __sanitizer_get_heap_size(); |
| 17 | assert(b - a > s / 2); |
| 18 | free(ptr: g); |
| 19 | int c = __sanitizer_get_heap_size(); |
| 20 | fprintf(stderr, format: "%d %d\n" , a, c); |
| 21 | if (atoi(nptr: argv[1]) == 1) |
| 22 | assert(c - a > s / 2); // NODRAIN |
| 23 | else |
| 24 | assert(c - a < s / 2); // DRAIN |
| 25 | } |
| 26 | |