Skip to content

Commit be4099e

Browse files
authoredOct 7, 2022
Fix memory leaks in test_capi (#98017)
1 parent f99bb20 commit be4099e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed
 

‎Lib/test/test_capi.py

+3
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,9 @@ def unraisable_hook(unraisable):
14951495
unraisable = unraisables[0]
14961496
self.assertIs(unraisable.object, d)
14971497
self.assertEqual(str(unraisable.exc_value), "boom!")
1498+
# avoid leaking reference cycles
1499+
del unraisable
1500+
del unraisables
14981501

14991502
def test_two_watchers(self):
15001503
d1 = {}

‎Modules/_testcapimodule.c

+3
Original file line numberDiff line numberDiff line change
@@ -5210,6 +5210,7 @@ dict_watch_callback(PyDict_WatchEvent event,
52105210
Py_DECREF(msg);
52115211
return -1;
52125212
}
5213+
Py_DECREF(msg);
52135214
return 0;
52145215
}
52155216

@@ -5224,8 +5225,10 @@ dict_watch_callback_second(PyDict_WatchEvent event,
52245225
return -1;
52255226
}
52265227
if (PyList_Append(g_dict_watch_events, msg) < 0) {
5228+
Py_DECREF(msg);
52275229
return -1;
52285230
}
5231+
Py_DECREF(msg);
52295232
return 0;
52305233
}
52315234

0 commit comments

Comments
 (0)