]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix memory leaks in test_capi (#98017)
authorCarl Meyer <carl@oddbird.net>
Fri, 7 Oct 2022 15:17:41 +0000 (08:17 -0700)
committerGitHub <noreply@github.com>
Fri, 7 Oct 2022 15:17:41 +0000 (08:17 -0700)
Lib/test/test_capi.py
Modules/_testcapimodule.c

index cb90d55941cae799aa13760bc29f5047f1f0e6b5..19367dfcc1ccbba430d691f2be0b54f746bc83c4 100644 (file)
@@ -1495,6 +1495,9 @@ class TestDictWatchers(unittest.TestCase):
         unraisable = unraisables[0]
         self.assertIs(unraisable.object, d)
         self.assertEqual(str(unraisable.exc_value), "boom!")
+        # avoid leaking reference cycles
+        del unraisable
+        del unraisables
 
     def test_two_watchers(self):
         d1 = {}
index c57dba4a5bf39e2c8799143eb5c6f52293eb1663..28fb43dce4c6cbceb127ae40b9052f8123cccadc 100644 (file)
@@ -5210,6 +5210,7 @@ dict_watch_callback(PyDict_WatchEvent event,
         Py_DECREF(msg);
         return -1;
     }
+    Py_DECREF(msg);
     return 0;
 }
 
@@ -5224,8 +5225,10 @@ dict_watch_callback_second(PyDict_WatchEvent event,
         return -1;
     }
     if (PyList_Append(g_dict_watch_events, msg) < 0) {
+        Py_DECREF(msg);
         return -1;
     }
+    Py_DECREF(msg);
     return 0;
 }