Fix memory leaks in test_capi (#98017)

This commit is contained in:
Carl Meyer 2022-10-07 08:17:41 -07:00 committed by GitHub
parent f99bb20cde
commit be4099e55d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View 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 = {}

View 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;
}