未验证 提交 723c4ae7 编写于 作者: J Jiabin Yang 提交者: GitHub

fix hook mem leak (#42857)

上级 75db5b86
...@@ -77,7 +77,9 @@ class PyTensorHook : public egr::TensorHook { ...@@ -77,7 +77,9 @@ class PyTensorHook : public egr::TensorHook {
PyObject* res = nullptr; PyObject* res = nullptr;
try { try {
res = PyObject_CallFunctionObjArgs(py_func_, ToPyObject(var), nullptr); PyObject* p_tmp_var = ToPyObject(var);
res = PyObject_CallFunctionObjArgs(py_func_, p_tmp_var, nullptr);
Py_DECREF(p_tmp_var);
} catch (platform::EnforceNotMet& e) { } catch (platform::EnforceNotMet& e) {
throw std::move(e); throw std::move(e);
} catch (std::exception& e) { } catch (std::exception& e) {
...@@ -94,7 +96,9 @@ class PyTensorHook : public egr::TensorHook { ...@@ -94,7 +96,9 @@ class PyTensorHook : public egr::TensorHook {
if (res == Py_None) { if (res == Py_None) {
return var; return var;
} }
return reinterpret_cast<TensorObject*>(res)->tensor; auto res_tensor = reinterpret_cast<TensorObject*>(res)->tensor;
Py_DECREF(res);
return res_tensor;
} }
private: private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册