From 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 17 Nov 2016 16:48:38 -0800 Subject: Integrated internal changes from Google --- src/google/protobuf/arena.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/google/protobuf/arena.cc') diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index aa4e587c..21fd1be6 100755 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -36,7 +36,7 @@ #ifdef ADDRESS_SANITIZER #include -#endif +#endif // ADDRESS_SANITIZER namespace google { namespace protobuf { @@ -141,7 +141,7 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n, // malloc but it's not yet usable until we return it as part of an allocation. ASAN_POISON_MEMORY_REGION( reinterpret_cast(b) + b->pos, b->size - b->pos); -#endif +#endif // ADDRESS_SANITIZER return b; } @@ -205,7 +205,7 @@ void* Arena::AllocFromBlock(Block* b, size_t n) { b->pos = p + n; #ifdef ADDRESS_SANITIZER ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast(b) + p, n); -#endif +#endif // ADDRESS_SANITIZER return reinterpret_cast(b) + p; } @@ -244,7 +244,7 @@ uint64 Arena::SpaceUsed() const { return space_used; } -pair Arena::SpaceAllocatedAndUsed() const { +std::pair Arena::SpaceAllocatedAndUsed() const { uint64 allocated = 0; uint64 used = 0; @@ -265,9 +265,19 @@ uint64 Arena::FreeBlocks() { space_allocated += (b->size); Block* next = b->next; if (next != NULL) { +#ifdef ADDRESS_SANITIZER + // This memory was provided by the underlying allocator as unpoisoned, so + // return it in an unpoisoned state. + ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast(b), b->size); +#endif // ADDRESS_SANITIZER options_.block_dealloc(b, b->size); } else { if (owns_first_block_) { +#ifdef ADDRESS_SANITIZER + // This memory was provided by the underlying allocator as unpoisoned, + // so return it in an unpoisoned state. + ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast(b), b->size); +#endif // ADDRESS_SANITIZER options_.block_dealloc(b, b->size); } else { // User passed in the first block, skip free'ing the memory. -- cgit v1.2.3