mirror of
https://github.com/larsimmisch/pyalsaaudio.git
synced 2026-05-30 18:07:02 +00:00
Fix memory leak on Python 3. Closes #2
This commit is contained in:
+12
-4
@@ -652,6 +652,7 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args)
|
|||||||
int res;
|
int res;
|
||||||
int datalen;
|
int datalen;
|
||||||
char *data;
|
char *data;
|
||||||
|
PyObject *rc = NULL;
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
if (!PyArg_ParseTuple(args,"s#:write",&data,&datalen))
|
if (!PyArg_ParseTuple(args,"s#:write",&data,&datalen))
|
||||||
@@ -690,15 +691,22 @@ static PyObject *alsapcm_write(alsapcm_t *self, PyObject *args)
|
|||||||
}
|
}
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
if (res == -EAGAIN)
|
if (res == -EAGAIN) {
|
||||||
return PyLong_FromLong(0);
|
rc = PyLong_FromLong(0);
|
||||||
|
}
|
||||||
else if (res < 0)
|
else if (res < 0)
|
||||||
{
|
{
|
||||||
PyErr_SetString(ALSAAudioError,snd_strerror(res));
|
PyErr_SetString(ALSAAudioError,snd_strerror(res));
|
||||||
return NULL;
|
}
|
||||||
|
else {
|
||||||
|
rc = PyLong_FromLong(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyLong_FromLong(res);
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyBuffer_Release(&buf);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(write_doc,
|
PyDoc_STRVAR(write_doc,
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Contributed by Stein Magnus Jodal
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import resource
|
||||||
|
import time
|
||||||
|
|
||||||
|
import alsaaudio
|
||||||
|
|
||||||
|
seconds = 0
|
||||||
|
max_rss = 0
|
||||||
|
device = alsaaudio.PCM()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
device.write(b'\x00' * 44100)
|
||||||
|
time.sleep(1)
|
||||||
|
seconds += 1
|
||||||
|
if seconds % 10 == 0:
|
||||||
|
prev_rss = max_rss
|
||||||
|
max_rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
|
||||||
|
diff_rss = max_rss - prev_rss
|
||||||
|
print('After %ds: max RSS %d kB, increased %d kB' % (
|
||||||
|
seconds, max_rss, diff_rss))
|
||||||
Reference in New Issue
Block a user