Skip to content

Commit 1cb7e7d

Browse files
committed
fix(allocation): fix ut
test=develop
1 parent c8f6e70 commit 1cb7e7d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

paddle/fluid/memory/allocation/allocator.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ void Allocator::Free(Allocation* allocation) { delete allocation; }
3636
const char* BadAlloc::what() const noexcept { return msg_.c_str(); }
3737

3838
void AllocationDeleter::operator()(Allocation* allocation) const {
39-
allocation->allocator()->Free(allocation);
39+
auto* allocator = allocation->allocator();
40+
if (allocator) {
41+
allocator->Free(allocation);
42+
} else {
43+
delete allocation; // Compatible for legacy allocation.
44+
}
4045
}
4146

4247
} // namespace allocation

paddle/fluid/memory/allocation/buffered_allocator.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void BufferedAllocator::FreeCache(size_t size) {
4141
while (!allocations_.empty()) { // free the largest
4242
auto it = --allocations_.end();
4343
cur += it->second->size();
44+
delete it->second.release();
4445
allocations_.erase(it);
4546
if (cur >= size) return;
4647
}

0 commit comments

Comments
 (0)