summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorEddie Elizondo <eelizondo@fb.com>2019-09-13 16:48:03 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-13 16:48:03 (GMT)
commita67ac2f2d9550e5a36d28f9b6eeacf6575dda2d5 (patch)
tree0cf5dc7d9e474ac658adb653d47a5d96646fada7 /Modules/_testcapimodule.c
parent14fd925a18fe3db0922a7d798e373102fe7a8a9c (diff)
downloadcpython-a67ac2f2d9550e5a36d28f9b6eeacf6575dda2d5.zip
cpython-a67ac2f2d9550e5a36d28f9b6eeacf6575dda2d5.tar.gz
cpython-a67ac2f2d9550e5a36d28f9b6eeacf6575dda2d5.tar.bz2
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
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index dee06de..4cca784 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -6304,7 +6304,7 @@ static void
heapctypesubclasswithfinalizer_finalize(PyObject *self)
{
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. */
PyErr_Fetch(&error_type, &error_value, &error_traceback);
@@ -6322,18 +6322,26 @@ heapctypesubclasswithfinalizer_finalize(PyObject *self)
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 = PyLong_FromSsize_t(Py_REFCNT(oldtype));
+ if (refcnt == 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 = PyLong_FromSsize_t(Py_REFCNT(newtype));
+ if (refcnt == NULL) {
+ goto cleanup_finalize;
+ }
+ if (PyObject_SetAttrString(newtype, "refcnt_in_del", refcnt) < 0) {
goto cleanup_finalize;
}
cleanup_finalize:
Py_XDECREF(oldtype);
Py_XDECREF(newtype);
+ Py_XDECREF(refcnt);
/* Restore the saved exception. */
PyErr_Restore(error_type, error_value, error_traceback);