diff --git a/mace/core/allocator.h b/mace/core/allocator.h index a35b2a2eba94686af1eb36e8b1bc286b5cbadeb3..a241fd4c004292adf263bb80dbb3bc701b6a1769 100644 --- a/mace/core/allocator.h +++ b/mace/core/allocator.h @@ -88,6 +88,9 @@ class CPUAllocator : public Allocator { LOG(WARNING) << "Allocate CPU Buffer with " << nbytes << " bytes failed because of" << strerror(errno); + if (data != NULL) { + free(data); + } *result = nullptr; return MaceStatus::MACE_OUT_OF_RESOURCES; } diff --git a/mace/core/runtime/opencl/opencl_allocator.cc b/mace/core/runtime/opencl/opencl_allocator.cc index 4d356d6f5cb99fd9e848de50740e48b3a8a5047c..4d0c235134729a76cb00ee1f77713fa23f93c0d9 100644 --- a/mace/core/runtime/opencl/opencl_allocator.cc +++ b/mace/core/runtime/opencl/opencl_allocator.cc @@ -58,6 +58,7 @@ MaceStatus OpenCLAllocator::New(size_t nbytes, void **result) const { LOG(WARNING) << "Allocate OpenCL Buffer with " << nbytes << " bytes failed because of" << OpenCLErrorToString(error); + delete buffer; *result = nullptr; return MaceStatus::MACE_OUT_OF_RESOURCES; } else { @@ -89,6 +90,7 @@ MaceStatus OpenCLAllocator::NewImage(const std::vector &image_shape, << image_shape[0] << ", " << image_shape[1] << "] failed because of" << OpenCLErrorToString(error); + delete cl_image; *result = nullptr; return MaceStatus::MACE_OUT_OF_RESOURCES; } else {