Skip to content

Commit c7a3b3a

Browse files
committed
Do not free nullptr and if a nullptr is freed, handle it correctly.
1 parent e755f6b commit c7a3b3a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

tensorflow/core/common_runtime/gpu/gpu_cudamallocasync_allocator.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ void* GpuCudaMallocAsyncAllocator::AllocateRaw(size_t alignment,
314314
}
315315
void GpuCudaMallocAsyncAllocator::DeallocateRaw(void* ptr) {
316316
#if TF_CUDA_MALLOC_ASYNC_SUPPORTED
317+
if (ptr == nullptr)
318+
return;
317319
if (auto result = cuMemFreeAsync(reinterpret_cast<const CUdeviceptr&>(ptr),
318320
cuda_stream_)) {
319321
if (result == CUDA_ERROR_DEINITIALIZED) {

tensorflow/core/common_runtime/gpu/gpu_device.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ BaseGPUDevice::BaseGPUDevice(const SessionOptions& options, const string& name,
397397

398398
BaseGPUDevice::~BaseGPUDevice() {
399399
delete gpu_device_info_;
400-
gpu_allocator_->DeallocateRaw(scratch_);
400+
if (scratch_)
401+
gpu_allocator_->DeallocateRaw(scratch_);
401402
device_context_->Unref();
402403
}
403404

0 commit comments

Comments
 (0)