未验证 提交 07afc29e 编写于 作者: L liu zhengxi 提交者: GitHub

Make api.cc malloc consistent with paddle_api.h for PaddleBuf (#22255)

上级 4f1da4ad
...@@ -85,7 +85,7 @@ void PaddleBuf::Resize(size_t length) { ...@@ -85,7 +85,7 @@ void PaddleBuf::Resize(size_t length) {
if (length_ >= length) return; if (length_ >= length) return;
if (memory_owned_) { if (memory_owned_) {
Free(); Free();
data_ = malloc(length); data_ = new char[length];
length_ = length; length_ = length;
memory_owned_ = true; memory_owned_ = true;
} else { } else {
...@@ -103,7 +103,7 @@ void PaddleBuf::Reset(void *data, size_t length) { ...@@ -103,7 +103,7 @@ void PaddleBuf::Reset(void *data, size_t length) {
void PaddleBuf::Free() { void PaddleBuf::Free() {
if (memory_owned_ && data_) { if (memory_owned_ && data_) {
PADDLE_ENFORCE_GT(length_, 0UL); PADDLE_ENFORCE_GT(length_, 0UL);
free(static_cast<char *>(data_)); delete[] static_cast<char *>(data_);
data_ = nullptr; data_ = nullptr;
length_ = 0; length_ = 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册