aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/arena.cc
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2016-11-17 16:48:38 -0800
committerGravatar Adam Cozzette <acozzette@google.com>2016-11-17 16:59:59 -0800
commit5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (patch)
tree0276f81f8848a05d84cd7e287b43d665e30f04e3 /src/google/protobuf/arena.cc
parente28286fa05d8327fd6c5aa70cfb3be558f0932b8 (diff)
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/arena.cc')
-rwxr-xr-xsrc/google/protobuf/arena.cc18
1 files changed, 14 insertions, 4 deletions
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 <sanitizer/asan_interface.h>
-#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<char*>(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<char*>(b) + p, n);
-#endif
+#endif // ADDRESS_SANITIZER
return reinterpret_cast<char*>(b) + p;
}
@@ -244,7 +244,7 @@ uint64 Arena::SpaceUsed() const {
return space_used;
}
-pair<uint64, uint64> Arena::SpaceAllocatedAndUsed() const {
+std::pair<uint64, uint64> 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<char*>(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<char*>(b), b->size);
+#endif // ADDRESS_SANITIZER
options_.block_dealloc(b, b->size);
} else {
// User passed in the first block, skip free'ing the memory.