diff --git a/imperative/python/src/tensor.cpp b/imperative/python/src/tensor.cpp index bce96e15f7e630731bc3d7c95e6f16bbb90b1294..57c8f8ff2efb21bbf9f7b99f077232f35111cd1d 100644 --- a/imperative/python/src/tensor.cpp +++ b/imperative/python/src/tensor.cpp @@ -615,7 +615,7 @@ PyArray_Descr* _dtype_promotion(PyObject*const* args, size_t nargs) { SmallVector 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; }