提交 bf509a71 编写于 作者: L liuqi

Fix memory leak when allocate memory failed.

上级 b26ce539
......@@ -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;
}
......
......@@ -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<size_t> &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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册