summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-30 06:52:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-30 06:52:53 (GMT)
commitbe1c60c3f68a0ec75727fda4811a6eeae3f19048 (patch)
tree18eb29c980f11098eedfa34c06ba15e9cacb2c66 /Objects
parent2c7b5a9d0d6587a38f24da1f96f581bad0d3ded6 (diff)
parent4aa867959f19ce92ccf999aa9f9dc4bd0b49ead7 (diff)
downloadcpython-be1c60c3f68a0ec75727fda4811a6eeae3f19048.zip
cpython-be1c60c3f68a0ec75727fda4811a6eeae3f19048.tar.gz
cpython-be1c60c3f68a0ec75727fda4811a6eeae3f19048.tar.bz2
Issue #23783: Fixed memory leak in PyObject_ClearWeakRefs() in case of
MemoryError.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/weakrefobject.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index c083f8f..d4d52e6 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -900,11 +900,9 @@ PyObject_ClearWeakRefs(PyObject *object)
if (*list != NULL) {
PyWeakReference *current = *list;
Py_ssize_t count = _PyWeakref_GetWeakrefCount(current);
- int restore_error = PyErr_Occurred() ? 1 : 0;
PyObject *err_type, *err_value, *err_tb;
- if (restore_error)
- PyErr_Fetch(&err_type, &err_value, &err_tb);
+ PyErr_Fetch(&err_type, &err_value, &err_tb);
if (count == 1) {
PyObject *callback = current->wr_callback;
@@ -922,8 +920,7 @@ PyObject_ClearWeakRefs(PyObject *object)
tuple = PyTuple_New(count * 2);
if (tuple == NULL) {
- if (restore_error)
- PyErr_Fetch(&err_type, &err_value, &err_tb);
+ _PyErr_ChainExceptions(err_type, err_value, err_tb);
return;
}
@@ -954,7 +951,7 @@ PyObject_ClearWeakRefs(PyObject *object)
}
Py_DECREF(tuple);
}
- if (restore_error)
- PyErr_Restore(err_type, err_value, err_tb);
+ assert(!PyErr_Occurred());
+ PyErr_Restore(err_type, err_value, err_tb);
}
}