File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
paddle/fluid/inference/api Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
9
See the License for the specific language governing permissions and
10
10
limitations under the License. */
11
11
12
- #include < glog/logging.h>
13
12
#include " paddle/fluid/inference/api/paddle_inference_api.h"
13
+ #include " paddle/fluid/platform/enforce.h"
14
14
15
15
namespace paddle {
16
16
@@ -64,13 +64,15 @@ PaddleBuf& PaddleBuf::operator=(PaddleBuf&& other) {
64
64
65
65
void PaddleBuf::Resize (size_t length) {
66
66
// Only the owned memory can be reset, the external memory can't be changed.
67
- if (length_ = = length) return ;
67
+ if (length_ > = length) return ;
68
68
if (memory_owned_) {
69
69
Free ();
70
+ data_ = malloc (length);
71
+ length_ = length;
72
+ memory_owned_ = true ;
73
+ } else {
74
+ PADDLE_THROW (" The memory is allocated externally, can not Resized" );
70
75
}
71
- data_ = new char [length];
72
- length_ = length;
73
- memory_owned_ = true ;
74
76
}
75
77
76
78
void PaddleBuf::Reset (void * data, size_t length) {
@@ -82,8 +84,8 @@ void PaddleBuf::Reset(void* data, size_t length) {
82
84
83
85
void PaddleBuf::Free () {
84
86
if (memory_owned_ && data_) {
85
- assert (length_ > 0 );
86
- delete[] static_cast <char *>(data_);
87
+ PADDLE_ENFORCE_GT (length_, 0 );
88
+ free ( static_cast <char *>(data_) );
87
89
data_ = nullptr ;
88
90
length_ = 0 ;
89
91
}
You can’t perform that action at this time.
0 commit comments