From 1cb7e7dda2684bfca9d030b9e5475df8d8eb1632 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Fri, 16 Nov 2018 14:05:19 +0800 Subject: [PATCH] fix(allocation): fix ut test=develop --- paddle/fluid/memory/allocation/allocator.cc | 7 ++++++- paddle/fluid/memory/allocation/buffered_allocator.cc | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/memory/allocation/allocator.cc b/paddle/fluid/memory/allocation/allocator.cc index 41b4234de54..51982ad97da 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 4b57ea86694..fc75abc9dfe 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; } -- GitLab