Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3053,8 +3053,10 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
len = 0;

a = newarrayobject(type, len, descr);
if (a == NULL)
if (a == NULL) {
Py_XDECREF(it);
return NULL;
}

if (len > 0 && !array_Check(initial, state)) {
Py_ssize_t i;
Expand All @@ -3063,11 +3065,13 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PySequence_GetItem(initial, i);
if (v == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
Comment on lines 3067 to 3069
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a common part for most cleanups. You can add a label and use goto statements in other places.

}
if (setarrayitem(a, i, v) != 0) {
Py_DECREF(v);
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}
Py_DECREF(v);
Expand All @@ -3079,6 +3083,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
v = array_array_frombytes((PyObject *)a, initial);
if (v == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}
Py_DECREF(v);
Expand All @@ -3089,6 +3094,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
wchar_t *ustr = PyUnicode_AsWideCharString(initial, &n);
if (ustr == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}

Expand All @@ -3109,6 +3115,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_UCS4 *ustr = PyUnicode_AsUCS4Copy(initial);
if (ustr == NULL) {
Py_DECREF(a);
Py_XDECREF(it);
return NULL;
}

Expand Down Expand Up @@ -3136,6 +3143,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return a;
}
}
Py_XDECREF(it);
PyErr_SetString(PyExc_ValueError,
"bad typecode (must be b, B, u, w, h, H, i, I, l, L, q, Q, f or d)");
return NULL;
Expand Down
Loading