Skip to content

Commit e8a6297

Browse files
committed
proper refcount cleanup in error cases.
1 parent e7fab86 commit e8a6297

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Objects/exceptions.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,6 @@ ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored))
18521852
if (state == NULL)
18531853
return NULL;
18541854
args = ((PyBaseExceptionObject *)self)->args;
1855-
assert(state != Py_None);
18561855
res = PyTuple_Pack(3, Py_TYPE(self), args, state);
18571856
Py_DECREF(state);
18581857
return res;
@@ -2274,11 +2273,10 @@ OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored))
22742273

22752274
if (!self->dict) {
22762275
self->dict = PyDict_New();
2277-
if (!self->dict) {
2278-
return NULL;
2279-
}
22802276
}
2281-
if (!BaseException_add_timestamp_to_dict((PyBaseExceptionObject*)self, self->dict)) {
2277+
if (!self->dict ||
2278+
!BaseException_add_timestamp_to_dict((PyBaseExceptionObject*)self, self->dict)) {
2279+
Py_DECREF(args);
22822280
return NULL;
22832281
}
22842282
res = PyTuple_Pack(3, Py_TYPE(self), args, self->dict);
@@ -2552,6 +2550,7 @@ AttributeError_getstate(PyAttributeErrorObject *self, PyObject *Py_UNUSED(ignore
25522550
return NULL;
25532551
}
25542552
if (!BaseException_add_timestamp_to_dict((PyBaseExceptionObject*)self, dict)) {
2553+
Py_DECREF(dict);
25552554
return NULL;
25562555
}
25572556
if (self->name && PyDict_SetItemString(dict, "name", self->name) < 0) {

0 commit comments

Comments
 (0)