diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h b/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h @@ -99,7 +99,7 @@ void Put(Cache *c, Callback cb, Node *ptr, uptr size) { uptr max_cache_size = GetMaxCacheSize(); - if (max_cache_size) { + if (max_cache_size && size <= GetMaxSize()) { c->Enqueue(cb, ptr, size); } else { // GetMaxCacheSize() == 0 only when GetMaxSize() == 0 (see Init). diff --git a/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp b/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp @@ -0,0 +1,25 @@ +// RUN: %clangxx_asan %s -o %t +// RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 1 +// RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 4 + +#include +#include +#include +#include + +void *g; + +int main(int argc, char **argv) { + int s = atoi(argv[1]) * 1024 * 1024; + int a = __sanitizer_get_heap_size(); + g = malloc(s); + int b = __sanitizer_get_heap_size(); + assert(b - a > s / 2); + free(g); + int c = __sanitizer_get_heap_size(); + fprintf(stderr, "%d %d\n", a, c); + if (atoi(argv[1]) == 1) + assert(c - a > s / 2); // NODRAIN + else + assert(c - a < s / 2); // DRAIN +}