aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/arena.cc
diff options
context:
space:
mode:
authorGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-20 16:18:53 -0800
committerGravatar Feng Xiao <xfxyjwf@gmail.com>2014-11-20 16:18:53 -0800
commit99aa0f9e8f1a88def7bdebf1385678559cda0707 (patch)
tree7ccb663ee9a1c722bf6062435ac705e83568c7e8 /src/google/protobuf/arena.cc
parent49bc8c09636ae61f9c685d121278c3738b9a809a (diff)
Down-integrate from internal code base.
Diffstat (limited to 'src/google/protobuf/arena.cc')
-rw-r--r--src/google/protobuf/arena.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc
index 17b095aa..be0d9e34 100644
--- a/src/google/protobuf/arena.cc
+++ b/src/google/protobuf/arena.cc
@@ -30,6 +30,10 @@
#include <google/protobuf/arena.h>
+#ifdef ADDRESS_SANITIZER
+#include <sanitizer/asan_interface.h>
+#endif
+
namespace google {
namespace protobuf {
@@ -91,6 +95,12 @@ Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n,
} else {
b->owner = me;
}
+#ifdef ADDRESS_SANITIZER
+ // Poison the rest of the block for ASAN. It was unpoisoned by the underlying
+ // 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
return b;
}
@@ -152,6 +162,9 @@ void* Arena::AllocateAligned(size_t n) {
void* Arena::AllocFromBlock(Block* b, size_t n) {
size_t p = b->pos;
b->pos = p + n;
+#ifdef ADDRESS_SANITIZER
+ ASAN_UNPOISON_MEMORY_REGION(reinterpret_cast<char*>(b) + p, n);
+#endif
return reinterpret_cast<char*>(b) + p;
}