summaryrefslogtreecommitdiff
path: root/libsanitizer/tsan/tsan_mman.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libsanitizer/tsan/tsan_mman.cc')
-rw-r--r--libsanitizer/tsan/tsan_mman.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/libsanitizer/tsan/tsan_mman.cc b/libsanitizer/tsan/tsan_mman.cc
index ba4252eccc5..9a8a524f262 100644
--- a/libsanitizer/tsan/tsan_mman.cc
+++ b/libsanitizer/tsan/tsan_mman.cc
@@ -58,8 +58,9 @@ void *user_alloc(ThreadState *thr, uptr pc, uptr sz, uptr align) {
void *p = allocator()->Allocate(&thr->alloc_cache, sz, align);
if (p == 0)
return 0;
- MBlock *b = (MBlock*)allocator()->GetMetaData(p);
+ MBlock *b = new(allocator()->GetMetaData(p)) MBlock;
b->size = sz;
+ b->head = 0;
b->alloc_tid = thr->unique_id;
b->alloc_stack_id = CurrentStackId(thr, pc);
if (CTX() && CTX()->initialized) {
@@ -90,6 +91,7 @@ void user_free(ThreadState *thr, uptr pc, void *p) {
if (CTX() && CTX()->initialized && thr->in_rtl == 1) {
MemoryRangeFreed(thr, pc, (uptr)p, b->size);
}
+ b->~MBlock();
allocator()->Deallocate(&thr->alloc_cache, p);
SignalUnsafeCall(thr, pc);
}
@@ -115,9 +117,11 @@ void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) {
}
MBlock *user_mblock(ThreadState *thr, void *p) {
- // CHECK_GT(thr->in_rtl, 0);
CHECK_NE(p, (void*)0);
- return (MBlock*)allocator()->GetMetaData(p);
+ Allocator *a = allocator();
+ void *b = a->GetBlockBegin(p);
+ CHECK_NE(b, 0);
+ return (MBlock*)a->GetMetaData(b);
}
void invoke_malloc_hook(void *ptr, uptr size) {