提交 e0fffa52 编写于 作者: M Megvii Engine Team

fix(mge/tensor): fix mem leak when getting value in trace

GitOrigin-RevId: 1dabd88e09fc0195eaa6cba822e6dcb4f7107dd8
上级 3a4e0598
......@@ -1002,8 +1002,7 @@ class CompiledTensorProxy:
else:
# c++ will throw TraceReadError
return None
if self._isscalar:
self.__value = self.__value.squeeze()
# c++ side will handle scalar case
return self.__value
def _dev_tensor(self):
......
......@@ -393,7 +393,9 @@ PyObject* TensorWrapper::numpy() {
throw TraceReadError("value of this tensor is not read in trace");
}
if (m_tensor->m_flags & Tensor::Flags::SCALAR) {
np_val = PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(np_val));
PyObject *np_scalar = PyArray_Squeeze(reinterpret_cast<PyArrayObject*>(np_val));
Py_DECREF(np_val);
return np_scalar;
}
return np_val;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册