From 09ac6206abf27b45e6d2cbe6f462d3c3886dfc62 Mon Sep 17 00:00:00 2001 From: Archit Mishra Date: Mon, 21 Aug 2017 12:02:17 -0700 Subject: [PATCH] Circumvent ASAN false positive Summary: Changes: * checks if ASAN mode is on, and uses malloc and free in the constructor and destructor Closes https://github.com/facebook/rocksdb/pull/2767 Differential Revision: D5671243 Pulled By: armishra fbshipit-source-id: 8e4ad0f7f163400c4effa8617d3b30134119d802 --- cache/lru_cache.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index a78a52dff..47e402336 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -234,19 +234,35 @@ void LRUCacheShard::EvictFromLRU(size_t charge, } void* LRUCacheShard::operator new(size_t size) { +#if __SANITIZE_ADDRESS__ + return malloc(size); +#else return port::cacheline_aligned_alloc(size); +#endif } void* LRUCacheShard::operator new[](size_t size) { +#if __SANITIZE_ADDRESS__ + return malloc(size); +#else return port::cacheline_aligned_alloc(size); +#endif } void LRUCacheShard::operator delete(void *memblock) { +#if __SANITIZE_ADDRESS__ + free(memblock); +#else port::cacheline_aligned_free(memblock); +#endif } void LRUCacheShard::operator delete[](void* memblock) { +#if __SANITIZE_ADDRESS__ + free(memblock); +#else port::cacheline_aligned_free(memblock); +#endif } void LRUCacheShard::SetCapacity(size_t capacity) {