diff --git a/tensorflow/c/eager/c_api.cc b/tensorflow/c/eager/c_api.cc index e70539ceefa..75271b6e826 100644 --- a/tensorflow/c/eager/c_api.cc +++ b/tensorflow/c/eager/c_api.cc @@ -537,7 +537,14 @@ void TFE_ContextAddFunctionDef(TFE_Context* ctx, } // extern "C" TFE_TensorHandle* TFE_NewTensorHandle(const tensorflow::Tensor& t) { - return new TFE_TensorHandle(t, nullptr); + TF_Status* status = TF_NewStatus(); + TFE_TensorHandle* tensor = TFE_NewTensorHandle(t, status); + if (TF_GetCode(status) != TF_OK) { + TF_DeleteStatus(status); + return nullptr; + } + TF_DeleteStatus(status); + return tensor; } const tensorflow::Tensor* TFE_TensorHandleUnderlyingTensorInHostMemory( diff --git a/tensorflow/c/eager/c_api.h b/tensorflow/c/eager/c_api.h index 24a80a8f5b5..88a0dd343f2 100644 --- a/tensorflow/c/eager/c_api.h +++ b/tensorflow/c/eager/c_api.h @@ -153,7 +153,7 @@ class Tensor; const tensorflow::Tensor* TFE_TensorHandleUnderlyingTensorInHostMemory( TFE_TensorHandle* h, TF_Status* status); -TFE_TensorHandle* TFE_NewTensorHandle(const tensorflow::Tensor& t, TF_Status* status); +TFE_TensorHandle* TFE_NewTensorHandle(const tensorflow::Tensor& t); #endif #endif // TENSORFLOW_C_EAGER_C_API_H_ diff --git a/tensorflow/python/eager/pywrap_tfe_src.cc b/tensorflow/python/eager/pywrap_tfe_src.cc index 311bbc9477c..655e3ec8491 100644 --- a/tensorflow/python/eager/pywrap_tfe_src.cc +++ b/tensorflow/python/eager/pywrap_tfe_src.cc @@ -347,14 +347,7 @@ TFE_TensorHandle* TFE_Py_NumpyToTensorHandle(PyObject* obj) { tensorflow::Tensor t; auto cppstatus = tensorflow::NdarrayToTensor(obj, &t); if (cppstatus.ok()) { - TF_Status* status = TF_NewStatus(); - TFE_TensorHandle* tensor = TFE_NewTensorHandle(t, status); - if (TF_GetCode(status) != TF_OK) { - TF_DeleteStatus(status); - return nullptr; - } - TF_DeleteStatus(status); - return tensor; + return TFE_NewTensorHandle(t); } else { tensorflow::mutex_lock l(exception_class_mutex); auto msg = tensorflow::strings::StrCat(