Skip to content

Commit

Permalink
Fix memory leaks in test_capi (python#98017)
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm authored Oct 7, 2022
1 parent f99bb20 commit be4099e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
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

0 comments on commit be4099e

Please sign in to comment.