diff --git a/paddle/fluid/memory/allocation/allocator.cc b/paddle/fluid/memory/allocation/allocator.cc index 41b4234de545ae35281bf9cf0f63509ec2c7a20d..51982ad97da5c7a592835c8567869143325a2cd1 100644 --- a/paddle/fluid/memory/allocation/allocator.cc +++ b/paddle/fluid/memory/allocation/allocator.cc @@ -36,7 +36,12 @@ void Allocator::Free(Allocation* allocation) { delete allocation; } const char* BadAlloc::what() const noexcept { return msg_.c_str(); } void AllocationDeleter::operator()(Allocation* allocation) const { - allocation->allocator()->Free(allocation); + auto* allocator = allocation->allocator(); + if (allocator) { + allocator->Free(allocation); + } else { + delete allocation; // Compatible for legacy allocation. + } } } // namespace allocation diff --git a/paddle/fluid/memory/allocation/buffered_allocator.cc b/paddle/fluid/memory/allocation/buffered_allocator.cc index 4b57ea86694e57c5542d0f1811bf3b4cce208cf1..fc75abc9dfee6c9df5bc87faa493002cc1fe6298 100644 --- a/paddle/fluid/memory/allocation/buffered_allocator.cc +++ b/paddle/fluid/memory/allocation/buffered_allocator.cc @@ -41,6 +41,7 @@ void BufferedAllocator::FreeCache(size_t size) { while (!allocations_.empty()) { // free the largest auto it = --allocations_.end(); cur += it->second->size(); + delete it->second.release(); allocations_.erase(it); if (cur >= size) return; }