aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c
diff options
context:
space:
mode:
authorGravatar James Keeling <jtkeeling@google.com>2018-07-24 11:11:35 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-24 11:23:35 -0700
commitd53830cddfc74105e46a4bdb703cb1154a288f8f (patch)
tree544e0bbb9dfdf5584e2068ab36969332b4a8ae37 /tensorflow/c
parentaef000ed3c2863a5cc7ccb5bf1fb46116e7f4f02 (diff)
Update TF_ApiDefMapGet to return nullptr if there is an error.
Previously it would return an allocated buffer, even if there was an error and the buffer was not usable. This could cause memory leaks if the caller did not manually delete the buffer. Because TF_DeleteBuffer has been updated to be safe to call on nullptr, it's still OK if callers attempt to delete this nullptr. PiperOrigin-RevId: 205858542
Diffstat (limited to 'tensorflow/c')
-rw-r--r--tensorflow/c/c_api.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/tensorflow/c/c_api.cc b/tensorflow/c/c_api.cc
index f516ce4f18..10bc8cdbee 100644
--- a/tensorflow/c/c_api.cc
+++ b/tensorflow/c/c_api.cc
@@ -2732,6 +2732,10 @@ TF_Buffer* TF_ApiDefMapGet(TF_ApiDefMap* api_def_map, const char* name,
TF_Buffer* ret = TF_NewBuffer();
status->status = MessageToBuffer(*api_def, ret);
+ if (!status->status.ok()) {
+ TF_DeleteBuffer(ret);
+ return nullptr;
+ }
return ret;
#endif // __ANDROID__
}