From 62ae2478670ff9b8f0c5b553afab9444b5dc59ae Mon Sep 17 00:00:00 2001
From: zilinzhu <zilinzhu@tencent.com>
Date: Wed, 15 Apr 2020 14:53:59 +0800
Subject: [PATCH] fix bug in keras when only pass run options will trigger
 segmentation fault

---
 tensorflow/python/client/tf_session_helper.cc | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/tensorflow/python/client/tf_session_helper.cc b/tensorflow/python/client/tf_session_helper.cc
index 78a1613c86c..67dddebe602 100644
--- a/tensorflow/python/client/tf_session_helper.cc
+++ b/tensorflow/python/client/tf_session_helper.cc
@@ -235,18 +235,13 @@ void RunCallableHelper(tensorflow::Session* session, int64_t handle,
     }
   }
 
-  // Allocate a RunMetadata protobuf object to receive the metadata,
-  // if the caller is expecting any.
-  std::unique_ptr<RunMetadata> run_metadata_proto;
-  if (run_metadata != nullptr) {
-    run_metadata_proto.reset(new RunMetadata);
-  }
+  RunMetadata run_metadata_proto;
 
   // Run the callable.
   std::vector<Tensor> output_tensors;
   Py_BEGIN_ALLOW_THREADS;
   s = session->RunCallable(handle, input_tensors, &output_tensors,
-                           run_metadata_proto.get());
+                           &run_metadata_proto);
   Py_END_ALLOW_THREADS;
 
   if (!s.ok()) {
@@ -256,7 +251,7 @@ void RunCallableHelper(tensorflow::Session* session, int64_t handle,
 
   // If requested, serialize the RunMetadata to pass it back to the caller.
   if (run_metadata != nullptr) {
-    s = MessageToBuffer(*run_metadata_proto, run_metadata);
+    s = MessageToBuffer(run_metadata_proto, run_metadata);
     if (!s.ok()) {
       Set_TF_Status_from_Status(out_status, s);
       return;