Remove memory leak in read variable call, and record gradient call.
authorAkshay Modi <nareshmodi@google.com>
Mon, 11 Jun 2018 23:27:12 +0000 (16:27 -0700)
committerAkshay Modi <nareshmodi@google.com>
Wed, 13 Jun 2018 19:47:09 +0000 (12:47 -0700)
Fix #19385

PiperOrigin-RevId: 200132949

tensorflow/python/eager/pywrap_tfe_src.cc

index 52b3268..6c9481c 100644 (file)
@@ -1873,6 +1873,8 @@ PyObject* RecordGradient(PyObject* op_name, PyObject* inputs, PyObject* attrs,
         delete backward_function;
       });
 
+  Py_DECREF(num_inputs);
+
   Py_RETURN_NONE;
 }
 
@@ -1931,8 +1933,10 @@ bool ReadVariableOp(const FastPathOpExecInfo& parent_op_exec_info,
     Py_INCREF(output->get());  // stay alive after since tuple steals.
     PyTuple_SET_ITEM(outputs.get(), 0, output->get());
 
-    if (!RecordGradient(GetPythonObjectFromString("ReadVariableOp"),
-                        inputs.get(), Py_None, outputs.get(), Py_None)) {
+    tensorflow::Safe_PyObjectPtr op_string(
+        GetPythonObjectFromString("ReadVariableOp"));
+    if (!RecordGradient(op_string.get(), inputs.get(), Py_None, outputs.get(),
+                        Py_None)) {
       return false;
     }
   }