Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks in test_capi #98017

Merged
merged 1 commit into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,9 @@ def unraisable_hook(unraisable):
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 = {}
Expand Down
3 changes: 3 additions & 0 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5210,6 +5210,7 @@ dict_watch_callback(PyDict_WatchEvent event,
Py_DECREF(msg);
return -1;
}
Py_DECREF(msg);
return 0;
}

Expand All @@ -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;
}

Expand Down