mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
bpo-38150 Fix refleak in the finalizer of a _testcapimodule type (GH-16115)
The PyLong created in the finalizer was not being cleaned up https://bugs.python.org/issue38150 Automerge-Triggered-By: @matrixise
This commit is contained in:
parent
14fd925a18
commit
a67ac2f2d9
1 changed files with 13 additions and 5 deletions
|
@ -6304,7 +6304,7 @@ static void
|
||||||
heapctypesubclasswithfinalizer_finalize(PyObject *self)
|
heapctypesubclasswithfinalizer_finalize(PyObject *self)
|
||||||
{
|
{
|
||||||
PyObject *error_type, *error_value, *error_traceback, *m;
|
PyObject *error_type, *error_value, *error_traceback, *m;
|
||||||
PyObject *oldtype = NULL, *newtype = NULL;
|
PyObject *oldtype = NULL, *newtype = NULL, *refcnt = NULL;
|
||||||
|
|
||||||
/* Save the current exception, if any. */
|
/* Save the current exception, if any. */
|
||||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||||
|
@ -6322,18 +6322,26 @@ heapctypesubclasswithfinalizer_finalize(PyObject *self)
|
||||||
if (PyObject_SetAttrString(self, "__class__", newtype) < 0) {
|
if (PyObject_SetAttrString(self, "__class__", newtype) < 0) {
|
||||||
goto cleanup_finalize;
|
goto cleanup_finalize;
|
||||||
}
|
}
|
||||||
if (PyObject_SetAttrString(
|
refcnt = PyLong_FromSsize_t(Py_REFCNT(oldtype));
|
||||||
oldtype, "refcnt_in_del", PyLong_FromSsize_t(Py_REFCNT(oldtype))) < 0) {
|
if (refcnt == NULL) {
|
||||||
goto cleanup_finalize;
|
goto cleanup_finalize;
|
||||||
}
|
}
|
||||||
if (PyObject_SetAttrString(
|
if (PyObject_SetAttrString(oldtype, "refcnt_in_del", refcnt) < 0) {
|
||||||
newtype, "refcnt_in_del", PyLong_FromSsize_t(Py_REFCNT(newtype))) < 0) {
|
goto cleanup_finalize;
|
||||||
|
}
|
||||||
|
Py_DECREF(refcnt);
|
||||||
|
refcnt = PyLong_FromSsize_t(Py_REFCNT(newtype));
|
||||||
|
if (refcnt == NULL) {
|
||||||
|
goto cleanup_finalize;
|
||||||
|
}
|
||||||
|
if (PyObject_SetAttrString(newtype, "refcnt_in_del", refcnt) < 0) {
|
||||||
goto cleanup_finalize;
|
goto cleanup_finalize;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup_finalize:
|
cleanup_finalize:
|
||||||
Py_XDECREF(oldtype);
|
Py_XDECREF(oldtype);
|
||||||
Py_XDECREF(newtype);
|
Py_XDECREF(newtype);
|
||||||
|
Py_XDECREF(refcnt);
|
||||||
|
|
||||||
/* Restore the saved exception. */
|
/* Restore the saved exception. */
|
||||||
PyErr_Restore(error_type, error_value, error_traceback);
|
PyErr_Restore(error_type, error_value, error_traceback);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue