Skip to content

Commit 93ded60

Browse files
committed
Update on "Ensure that deleter is called even for a no-data tensor."
Summary: When using a custom deleter InefficientStdFunctionContext was using a std::unique_ptr<> to store the pointer and call the deleter - but this failed to call the deleter if the pointer was null. Since we have a separate holder class anyway take out the std::unique_ptr<> and call the deleter directly. Fixes #117273 Test Plan: [ghstack-poisoned]
1 parent 3c7cc1d commit 93ded60

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

c10/core/Allocator.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,8 @@ struct C10_API Allocator {
225225
struct C10_API InefficientStdFunctionContext {
226226
void* ptr_;
227227
std::function<void(void*)> deleter_;
228-
InefficientStdFunctionContext(
229-
void* ptr,
230-
std::function<void(void*)> deleter)
231-
: ptr_(ptr), deleter_(std::move(deleter)) {}
228+
InefficientStdFunctionContext(void* ptr, std::function<void(void*)> deleter)
229+
: ptr_(ptr), deleter_(std::move(deleter)) {}
232230
~InefficientStdFunctionContext() {
233231
if (deleter_) {
234232
deleter_(ptr_);

0 commit comments

Comments
 (0)