Fix various minor memory leaks in the tests (found by Valgrind in #2746) (#2758)

* Fix leak in the test_copy_move::test_move_fallback

* Fix leaking PyMethodDef in test_class::test_implicit_conversion_life_support

* Plumb leak in test_buffer, occuring when a mutable buffer is requested for a read-only object, and enable test_buffer.py

* Fix weird return_value_policy::reference in test_stl_binders, and enable those tests

* Cleanup nodelete holder objects in test_smart_ptr, and enable those tests
This commit is contained in:
Yannick Jadoul
2021-01-01 17:05:22 +01:00
committed by GitHub
parent e612043d43
commit e57dd4717e
8 changed files with 68 additions and 26 deletions

View File

@@ -125,7 +125,9 @@ def test_unique_nodelete():
cstats = ConstructorStats.get(m.MyObject4)
assert cstats.alive() == 1
del o
assert cstats.alive() == 1 # Leak, but that's intentional
assert cstats.alive() == 1
m.MyObject4.cleanup_all_instances()
assert cstats.alive() == 0
def test_unique_nodelete4a():
@@ -134,19 +136,25 @@ def test_unique_nodelete4a():
cstats = ConstructorStats.get(m.MyObject4a)
assert cstats.alive() == 1
del o
assert cstats.alive() == 1 # Leak, but that's intentional
assert cstats.alive() == 1
m.MyObject4a.cleanup_all_instances()
assert cstats.alive() == 0
def test_unique_deleter():
m.MyObject4a(0)
o = m.MyObject4b(23)
assert o.value == 23
cstats4a = ConstructorStats.get(m.MyObject4a)
assert cstats4a.alive() == 2 # Two because of previous test
assert cstats4a.alive() == 2
cstats4b = ConstructorStats.get(m.MyObject4b)
assert cstats4b.alive() == 1
del o
assert cstats4a.alive() == 1 # Should now only be one leftover from previous test
assert cstats4a.alive() == 1 # Should now only be one leftover
assert cstats4b.alive() == 0 # Should be deleted
m.MyObject4a.cleanup_all_instances()
assert cstats4a.alive() == 0
assert cstats4b.alive() == 0
def test_large_holder():