Skip to content

Commit

Permalink
Fix memory leak for multiple constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
daanzu committed Sep 4, 2024
1 parent 1b2657e commit ef98994
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cbits/pywebrtcvad.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ static PyObject* vad_create(PyObject *self, PyObject *args)
if (WebRtcVad_Create(&handle)) {
return NULL;
}
vadptr = PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
return Py_BuildValue("O", vadptr);
return PyCapsule_New(handle, "WebRtcVadPtr", vad_free);
}

static PyObject* vad_init(PyObject *self, PyObject *vadptr)
Expand Down
4 changes: 2 additions & 2 deletions test_webrtcvad.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _profile_memory(self, threshold_ratio):
end_memory - start_memory,
start_memory * threshold_ratio)

@unittest.skipIf(platform.python_implementation() == 'PyPy', "fails on pypy, possibly due to inaccuracy in memory tracking?")
@unittest.skipIf(platform.python_implementation() == 'PyPy', "fails on pypy, possibly due to inaccuracy in memory tracking")
def test_leak_linear_usage(self):
file_name = os.path.join(os.path.dirname(__file__), 'leak-test.wav')
sound, fs = self._load_wave(file_name)
Expand All @@ -114,7 +114,7 @@ def test_leak_linear_usage(self):
find_voice = True
self.assertTrue(find_voice)

@unittest.expectedFailure
@unittest.skipIf(platform.python_implementation() == 'PyPy', "fails on pypy, possibly due to inaccuracy in memory tracking")
def test_leak_constructor(self):
nrepeats = 100000
with self._profile_memory(0.1):
Expand Down

0 comments on commit ef98994

Please sign in to comment.