[Python-checkins] (no subject)

Stéphane Wirtel webhook-mailer at python.org
Fri Sep 13 13:10:57 EDT 2019




To: python-checkins at python.org
Subject: [3.8] bpo-38150: Fix refleak in the finalizer of a _testcapimodule
 type (GH-16115) (GH-16118)
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

https://github.com/python/cpython/commit/53ff2ca89feb90c1fbf2605321bcef35b457=
f16f
commit: 53ff2ca89feb90c1fbf2605321bcef35b457f16f
branch: 3.8
author: St=C3=A9phane Wirtel <stephane at wirtel.be>
committer: GitHub <noreply at github.com>
date: 2019-09-13T18:10:53+01:00
summary:

[3.8] bpo-38150: Fix refleak in the finalizer of a _testcapimodule type (GH-1=
6115) (GH-16118)

The PyLong created in the finalizer was not being cleaned up

https://bugs.python.org/issue38150

Automerge-Triggered-By: @matrixise
(cherry picked from commit a67ac2f2d9550e5a36d28f9b6eeacf6575dda2d5)

Co-authored-by: Eddie Elizondo <eelizondo at fb.com>

files:
M Modules/_testcapimodule.c

diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index cb9206ca4eba..cccf9249040d 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -6090,7 +6090,7 @@ static void
 heapctypesubclasswithfinalizer_finalize(PyObject *self)
 {
     PyObject *error_type, *error_value, *error_traceback, *m;
-    PyObject *oldtype =3D NULL, *newtype =3D NULL;
+    PyObject *oldtype =3D NULL, *newtype =3D NULL, *refcnt =3D NULL;
=20
     /* Save the current exception, if any. */
     PyErr_Fetch(&error_type, &error_value, &error_traceback);
@@ -6108,18 +6108,26 @@ heapctypesubclasswithfinalizer_finalize(PyObject *sel=
f)
     if (PyObject_SetAttrString(self, "__class__", newtype) < 0) {
         goto cleanup_finalize;
     }
-    if (PyObject_SetAttrString(
-        oldtype, "refcnt_in_del", PyLong_FromSsize_t(Py_REFCNT(oldtype))) < =
0) {
+    refcnt =3D PyLong_FromSsize_t(Py_REFCNT(oldtype));
+    if (refcnt =3D=3D NULL) {
         goto cleanup_finalize;
     }
-    if (PyObject_SetAttrString(
-        newtype, "refcnt_in_del", PyLong_FromSsize_t(Py_REFCNT(newtype))) < =
0) {
+    if (PyObject_SetAttrString(oldtype, "refcnt_in_del", refcnt) < 0) {
+        goto cleanup_finalize;
+    }
+    Py_DECREF(refcnt);
+    refcnt =3D PyLong_FromSsize_t(Py_REFCNT(newtype));
+    if (refcnt =3D=3D NULL) {
+        goto cleanup_finalize;
+    }
+    if (PyObject_SetAttrString(newtype, "refcnt_in_del", refcnt) < 0) {
         goto cleanup_finalize;
     }
=20
 cleanup_finalize:
     Py_XDECREF(oldtype);
     Py_XDECREF(newtype);
+    Py_XDECREF(refcnt);
=20
     /* Restore the saved exception. */
     PyErr_Restore(error_type, error_value, error_traceback);



More information about the Python-checkins mailing list