Skip to content

Commit b44ffc8

Browse files
mpaoliniserhiy-storchaka
authored andcommitted
bpo-38677: Fix arraymodule error handling in module initialization. (GH-17039)
1 parent 57d3ab8 commit b44ffc8

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Modules/arraymodule.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,9 +3040,15 @@ array_modexec(PyObject *m)
30403040
Py_TYPE(&PyArrayIter_Type) = &PyType_Type;
30413041

30423042
Py_INCREF((PyObject *)&Arraytype);
3043-
PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype);
3043+
if (PyModule_AddObject(m, "ArrayType", (PyObject *)&Arraytype) < 0) {
3044+
Py_DECREF((PyObject *)&Arraytype);
3045+
return -1;
3046+
}
30443047
Py_INCREF((PyObject *)&Arraytype);
3045-
PyModule_AddObject(m, "array", (PyObject *)&Arraytype);
3048+
if (PyModule_AddObject(m, "array", (PyObject *)&Arraytype) < 0) {
3049+
Py_DECREF((PyObject *)&Arraytype);
3050+
return -1;
3051+
}
30463052

30473053
for (descr=descriptors; descr->typecode != '\0'; descr++) {
30483054
size++;
@@ -3053,13 +3059,11 @@ array_modexec(PyObject *m)
30533059
*p++ = (char)descr->typecode;
30543060
}
30553061
typecodes = PyUnicode_DecodeASCII(buffer, p - buffer, NULL);
3056-
3057-
PyModule_AddObject(m, "typecodes", typecodes);
3058-
3059-
if (PyErr_Occurred()) {
3060-
Py_DECREF(m);
3061-
m = NULL;
3062+
if (PyModule_AddObject(m, "typecodes", typecodes) < 0) {
3063+
Py_XDECREF(typecodes);
3064+
return -1;
30623065
}
3066+
30633067
return 0;
30643068
}
30653069

0 commit comments

Comments
 (0)