Skip to content

Commit 28545e5

Browse files
committed
move decref
1 parent 8b5e4ed commit 28545e5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Objects/exceptions.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,15 +1868,19 @@ static PyObject *
18681868
ImportError_repr(PyObject *self)
18691869
{
18701870
int hasargs = PyTuple_GET_SIZE(((PyBaseExceptionObject *)self)->args) != 0;
1871-
PyObject *r = BaseException_repr(self);
18721871
PyImportErrorObject *exc = PyImportErrorObject_CAST(self);
18731872
PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
18741873
if (writer == NULL) {
18751874
goto error;
18761875
}
1877-
if (PyUnicodeWriter_WriteSubstring(writer, r, 0, PyUnicode_GET_LENGTH(r)-1) < 0) {
1876+
PyObject *r = BaseException_repr(self);
1877+
if (PyUnicodeWriter_WriteSubstring(
1878+
writer, r, 0, PyUnicode_GET_LENGTH(r) - 1) < 0)
1879+
{
1880+
Py_XDECREF(r);
18781881
goto error;
18791882
}
1883+
Py_XDECREF(r);
18801884
if (exc->name) {
18811885
if (hasargs) {
18821886
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
@@ -1898,11 +1902,14 @@ ImportError_repr(PyObject *self)
18981902
goto error;
18991903
}
19001904
}
1901-
if (PyUnicodeWriter_WriteASCII(writer, ")", 1) < 0) goto error;
1905+
1906+
if (PyUnicodeWriter_WriteASCII(writer, ")", 1) < 0) {
1907+
goto error;
1908+
}
1909+
19021910
return PyUnicodeWriter_Finish(writer);
19031911

19041912
error:
1905-
Py_XDECREF(r);
19061913
PyUnicodeWriter_Discard(writer);
19071914
return NULL;
19081915
}
@@ -1932,7 +1939,9 @@ static PyTypeObject _PyExc_ImportError = {
19321939
.tp_repr = ImportError_repr,
19331940
.tp_str = ImportError_str,
19341941
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1935-
.tp_doc = PyDoc_STR("Import can't find module, or can't find name in module."),
1942+
.tp_doc = PyDoc_STR(
1943+
"Import can't find module, "
1944+
"or can't find name in module."),
19361945
.tp_traverse = ImportError_traverse,
19371946
.tp_clear = ImportError_clear,
19381947
.tp_methods = ImportError_methods,

0 commit comments

Comments
 (0)