未验证 提交 c46f2ddb 编写于 作者: C Chen Weihang 提交者: GitHub

fix python hook mem leak (#40716)

上级 8e4e19ab
...@@ -119,7 +119,11 @@ class PyVariableWrapperHook : public imperative::VariableWrapperHook { ...@@ -119,7 +119,11 @@ class PyVariableWrapperHook : public imperative::VariableWrapperHook {
return var; return var;
} }
return PyObjectCast<std::shared_ptr<imperative::VarBase>>(res)->SharedVar(); auto res_varbase = PyObjectCast<std::shared_ptr<imperative::VarBase>>(res);
// Here the reference count of `res` is 2, so we decreases the reference
// count manually to avoid memory leaks
Py_DECREF(res);
return res_varbase->SharedVar();
} }
private: private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册