diff options
Diffstat (limited to 'tensorflow/c/c_api.cc')
-rw-r--r-- | tensorflow/c/c_api.cc | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc index 14988fbc4d..5e236a81fb 100644 --- a/tensorflow/c/c_api.cc +++ b/tensorflow/c/c_api.cc @@ -37,6 +37,7 @@ limitations under the License. #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/strings/strcat.h" +#include "tensorflow/core/platform/mem.h" #include "tensorflow/core/platform/mutex.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/thread_annotations.h" @@ -159,11 +160,13 @@ Status MessageToBuffer(const tensorflow::protobuf::Message& in, return InvalidArgument("Passing non-empty TF_Buffer is invalid."); } const auto proto_size = in.ByteSize(); - void* buf = malloc(proto_size); + void* buf = tensorflow::port::Malloc(proto_size); in.SerializeToArray(buf, proto_size); out->data = buf; out->length = proto_size; - out->data_deallocator = [](void* data, size_t length) { free(data); }; + out->data_deallocator = [](void* data, size_t length) { + tensorflow::port::Free(data); + }; return Status::OK(); } @@ -287,13 +290,15 @@ void TF_SetConfig(TF_SessionOptions* options, const void* proto, TF_Buffer* TF_NewBuffer() { return new TF_Buffer{nullptr, 0, nullptr}; } TF_Buffer* TF_NewBufferFromString(const void* proto, size_t proto_len) { - void* copy = malloc(proto_len); + void* copy = tensorflow::port::Malloc(proto_len); memcpy(copy, proto, proto_len); TF_Buffer* buf = new TF_Buffer; buf->data = copy; buf->length = proto_len; - buf->data_deallocator = [](void* data, size_t length) { free(data); }; + buf->data_deallocator = [](void* data, size_t length) { + tensorflow::port::Free(data); + }; return buf; } @@ -694,7 +699,7 @@ TF_Library* TF_LoadLibrary(const char* library_filename, TF_Status* status) { TF_Buffer TF_GetOpList(TF_Library* lib_handle) { return lib_handle->op_list; } void TF_DeleteLibraryHandle(TF_Library* lib_handle) { - free(const_cast<void*>(lib_handle->op_list.data)); + tensorflow::port::Free(const_cast<void*>(lib_handle->op_list.data)); delete lib_handle; } |