From d53830cddfc74105e46a4bdb703cb1154a288f8f Mon Sep 17 00:00:00 2001 From: James Keeling Date: Tue, 24 Jul 2018 11:11:35 -0700 Subject: 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 --- tensorflow/c/c_api.cc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tensorflow/c') 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__ } -- cgit v1.2.3