diff --git a/paddle/fluid/memory/allocation/buffered_allocator.cc b/paddle/fluid/memory/allocation/buffered_allocator.cc index ca67765044c8819911756a11b37751e84e910e3c..18d02f6f657569e61d6585fc6fe53e04fbb1c732 100644 --- a/paddle/fluid/memory/allocation/buffered_allocator.cc +++ b/paddle/fluid/memory/allocation/buffered_allocator.cc @@ -36,20 +36,16 @@ BufferedAllocator::~BufferedAllocator() { FreeCache(-1UL); } std::unique_ptr BufferedAllocator::Allocate(size_t size, Allocator::Attr attr) { - std::unique_ptr result; { platform::LockGuardPtr guard(mtx_); auto it = allocations_.lower_bound(size); if (it != allocations_.end() && it->first < size * 2) { - result = std::move(it->second); + std::unique_ptr result(std::move(it->second)); allocations_.erase(it); + return result; } } - if (result) { - return result; - } - try { return underlying_allocator_->Allocate(size, attr); } catch (BadAlloc&) {