From: Carl Meyer Date: Fri, 7 Oct 2022 15:17:41 +0000 (-0700) Subject: Fix memory leaks in test_capi (#98017) X-Git-Tag: v3.12.0a1~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be4099e55d30a2991b46add59ee96c531904c144;p=thirdparty%2FPython%2Fcpython.git Fix memory leaks in test_capi (#98017) --- diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index cb90d55941ca..19367dfcc1cc 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 c57dba4a5bf3..28fb43dce4c6 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; }