From be4099e55d30a2991b46add59ee96c531904c144 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 7 Oct 2022 08:17:41 -0700 Subject: Fix memory leaks in test_capi (#98017) --- Lib/test/test_capi.py | 3 +++ Modules/_testcapimodule.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index cb90d55..19367df 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -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 = {} diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c57dba4..28fb43d 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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; } -- cgit v0.12