diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -256,36 +256,36 @@ Found = true; Entry = Entries[I]; Entries[I].CommitBase = 0; + EntriesCount--; break; } } - if (Found) { - *H = reinterpret_cast( - LargeBlock::addHeaderTag(HeaderPos)); - *Zeroed = Entry.Time == 0; - if (useMemoryTagging(Options)) - setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0, &Entry.Data); - uptr NewBlockBegin = reinterpret_cast(*H + 1); - if (useMemoryTagging(Options)) { - if (*Zeroed) - storeTags(LargeBlock::addHeaderTag(Entry.CommitBase), - NewBlockBegin); - else if (Entry.BlockBegin < NewBlockBegin) - storeTags(Entry.BlockBegin, NewBlockBegin); - else - storeTags(untagPointer(NewBlockBegin), - untagPointer(Entry.BlockBegin)); - } - (*H)->CommitBase = Entry.CommitBase; - (*H)->CommitSize = Entry.CommitSize; - (*H)->MapBase = Entry.MapBase; - (*H)->MapSize = Entry.MapSize; - (*H)->Data = Entry.Data; + if (!Found) + return false; - ScopedLock L(Mutex); - EntriesCount--; + *H = reinterpret_cast( + LargeBlock::addHeaderTag(HeaderPos)); + *Zeroed = Entry.Time == 0; + if (useMemoryTagging(Options)) + setMemoryPermission(Entry.CommitBase, Entry.CommitSize, 0, &Entry.Data); + uptr NewBlockBegin = reinterpret_cast(*H + 1); + if (useMemoryTagging(Options)) { + if (*Zeroed) { + storeTags(LargeBlock::addHeaderTag(Entry.CommitBase), + NewBlockBegin); + } else if (Entry.BlockBegin < NewBlockBegin) { + storeTags(Entry.BlockBegin, NewBlockBegin); + } else { + storeTags(untagPointer(NewBlockBegin), + untagPointer(Entry.BlockBegin)); + } } - return Found; + (*H)->CommitBase = Entry.CommitBase; + (*H)->CommitSize = Entry.CommitSize; + (*H)->MapBase = Entry.MapBase; + (*H)->MapSize = Entry.MapSize; + (*H)->Data = Entry.Data; + return true; } bool canCache(uptr Size) {