diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -267,6 +267,17 @@ bool UnlockRequired; auto *TSD = TSDRegistry.getTSDAndLock(&UnlockRequired); Block = TSD->Cache.allocate(ClassId); + // If the allocation failed, the most likely reason with a 64-bit primary + // is the region being full. In that event, retry once using the + // immediately larger class (except if the failing class was already the + // largest). This will waste some memory but will allow the application to + // not fail. + if (SCUDO_ANDROID && SCUDO_CAN_USE_PRIMARY64) { + if (UNLIKELY(!Block)) { + if (ClassId < SizeClassMap::LargestClassId) + Block = TSD->Cache.allocate(++ClassId); + } + } if (UnlockRequired) TSD->unlock(); } else {