1// Test that LargeAllocator unpoisons memory before releasing it to the OS. 2// RUN: %clangxx_asan %s -o %t 3// The memory is released only when the deallocated chunk leaves the quarantine, 4// otherwise the mmap(p, ...) call overwrites the malloc header. 5// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t 6 7#include <assert.h> 8#include <string.h> 9#include <sys/mman.h> 10#include <stdlib.h> 11#include <unistd.h> 12 13#ifdef __ANDROID__ 14#include <malloc.h> 15void *my_memalign(size_t boundary, size_t size) { 16 return memalign(boundary, size); 17} 18#else 19void *my_memalign(size_t boundary, size_t size) { 20 void *p; 21 posix_memalign(&p, boundary, size); 22 return p; 23} 24#endif 25 26int main() { 27 const long kPageSize = sysconf(_SC_PAGESIZE); 28 void *p = my_memalign(kPageSize, 1024 * 1024); 29 free(p); 30 31 char *q = (char *)mmap(p, kPageSize, PROT_READ | PROT_WRITE, 32 MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0); 33 assert(q == p); 34 35 memset(q, 42, kPageSize); 36 37 munmap(q, kPageSize); 38 return 0; 39} 40