diff options
author | James Keeling <jtkeeling@google.com> | 2018-07-24 11:11:35 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-07-24 11:23:35 -0700 |
commit | d53830cddfc74105e46a4bdb703cb1154a288f8f (patch) | |
tree | 544e0bbb9dfdf5584e2068ab36969332b4a8ae37 | |
parent | aef000ed3c2863a5cc7ccb5bf1fb46116e7f4f02 (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
-rw-r--r-- | tensorflow/c/c_api.cc | 4 |
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__ } |