Issue #23783: Fixed memory leak in PyObject_ClearWeakRefs() in case of

MemoryError.
This commit is contained in:
Serhiy Storchaka 2015-03-30 09:53:06 +03:00
parent aa64c46ac9
commit 07e03ab9f9
1 changed files with 4 additions and 7 deletions

View File

@ -924,11 +924,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;
@ -946,8 +944,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_ReplaceException(err_type, err_value, err_tb);
return;
}
@ -978,7 +975,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);
}
}