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

fix(imperative/tensor): fix Py_DECREF on uninitialized pointer

GitOrigin-RevId: 889255537ea351603bed2d60b60467b675d0dec1
上级 10d9d77e
......@@ -615,7 +615,7 @@ PyArray_Descr* _dtype_promotion(PyObject*const* args, size_t nargs) {
SmallVector<PyArray_Descr*> scalars;
bool is_tuple = false;
PyObject* tuple;
PyObject* tuple = nullptr;
if (nargs == 1 && (PyTuple_Check(args[0]) || PyList_Check(args[0]))) {
if (PyList_Check(args[0])) {
tuple = PyList_AsTuple(args[0]);
......@@ -664,13 +664,13 @@ PyArray_Descr* _dtype_promotion(PyObject*const* args, size_t nargs) {
}
for (auto *p: tensors) { Py_DECREF(p); }
for (auto *p: scalars) { Py_DECREF(p); }
Py_DECREF(tuple);
Py_XDECREF(tuple);
return res;
}
CompNode _get_device(PyObject*const* args, size_t nargs) {
bool is_tuple = false;
PyObject* tuple;
PyObject* tuple = nullptr;
if (nargs == 1 && (PyTuple_Check(args[0]) || PyList_Check(args[0]))) {
if (PyList_Check(args[0])) {
tuple = PyList_AsTuple(args[0]);
......@@ -702,7 +702,7 @@ CompNode _get_device(PyObject*const* args, size_t nargs) {
if (!valid) {
mgb_assert(0, "expect at least 1 device");
}
Py_DECREF(tuple);
Py_XDECREF(tuple);
return cn;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册