@@ -167,10 +167,10 @@ class LargeChunkHeader {
167
167
AsanChunk *chunk_header;
168
168
169
169
public:
170
- AsanChunk *Get () {
170
+ AsanChunk *Get () const {
171
171
return atomic_load (&magic, memory_order_acquire) == kAllocBegMagic
172
172
? chunk_header
173
- : reinterpret_cast <AsanChunk *>( this ) ;
173
+ : nullptr ;
174
174
}
175
175
176
176
void Set (AsanChunk *p) {
@@ -510,13 +510,10 @@ struct Allocator {
510
510
uptr needed_size = rounded_size + rz_size;
511
511
if (alignment > min_alignment)
512
512
needed_size += alignment;
513
- bool using_primary_allocator = true ;
514
513
// If we are allocating from the secondary allocator, there will be no
515
514
// automatic right redzone, so add the right redzone manually.
516
- if (!PrimaryAllocator::CanAllocate (needed_size, alignment)) {
515
+ if (!PrimaryAllocator::CanAllocate (needed_size, alignment))
517
516
needed_size += rz_size;
518
- using_primary_allocator = false ;
519
- }
520
517
CHECK (IsAligned (needed_size, min_alignment));
521
518
if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize ||
522
519
size > max_user_defined_malloc_size) {
@@ -568,13 +565,6 @@ struct Allocator {
568
565
m->alloc_type = alloc_type;
569
566
CHECK (size);
570
567
m->SetUsedSize (size);
571
- if (using_primary_allocator) {
572
- CHECK (allocator.FromPrimary (allocated));
573
- } else {
574
- CHECK (!allocator.FromPrimary (allocated));
575
- uptr *meta = reinterpret_cast <uptr *>(allocator.GetMetaData (allocated));
576
- meta[1 ] = chunk_beg;
577
- }
578
568
m->user_requested_alignment_log = user_requested_alignment_log;
579
569
580
570
m->SetAllocContext (t ? t->tid () : 0 , StackDepotPut (*stack));
@@ -782,15 +772,12 @@ struct Allocator {
782
772
AsanChunk *GetAsanChunk (void *alloc_beg) {
783
773
if (!alloc_beg)
784
774
return nullptr ;
785
- AsanChunk *p = nullptr ;
786
- if (!allocator.FromPrimary (alloc_beg)) {
787
- uptr *meta = reinterpret_cast <uptr *>(allocator.GetMetaData (alloc_beg));
788
- p = reinterpret_cast <AsanChunk *>(meta[1 ]);
789
- } else {
790
- p = reinterpret_cast <LargeChunkHeader *>(alloc_beg)->Get ();
775
+ AsanChunk *p = reinterpret_cast <LargeChunkHeader *>(alloc_beg)->Get ();
776
+ if (!p) {
777
+ if (!allocator.FromPrimary (alloc_beg))
778
+ return nullptr ;
779
+ p = reinterpret_cast <AsanChunk *>(alloc_beg);
791
780
}
792
- if (!p)
793
- return nullptr ;
794
781
u8 state = atomic_load (&p->chunk_state , memory_order_relaxed);
795
782
// It does not guaranty that Chunk is initialized, but it's
796
783
// definitely not for any other value.
0 commit comments