From 7c785e6842c286b9c65e4fee8b755cfeeaefcda9 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Mon, 18 Apr 2016 21:14:41 +0200 Subject: [PATCH] ext/py-filter.c: continue fixing memory leak (#49) --- python/ext/py-filter.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/ext/py-filter.c b/python/ext/py-filter.c index 416bba83..ab1ee767 100644 --- a/python/ext/py-filter.c +++ b/python/ext/py-filter.c @@ -5,6 +5,7 @@ typedef struct PyObject_HEAD aubio_filter_t * o; uint_t order; + fvec_t *out; } Py_filter; static char Py_filter_doc[] = "filter object"; @@ -47,13 +48,14 @@ Py_filter_init (Py_filter * self, PyObject * args, PyObject * kwds) if (self->o == NULL) { return -1; } - + self->out = new_fvec(Py_default_vector_length); return 0; } static void Py_filter_del (Py_filter * self) { + del_fvec(self->out); del_aubio_filter (self->o); self->ob_type->tp_free ((PyObject *) self); } @@ -78,10 +80,14 @@ Py_filter_do(Py_filter * self, PyObject * args) return NULL; } + // reallocate the output if needed + if (vec->length != self->out->length) { + del_fvec(self->out); + self->out = new_fvec(vec->length); + } // compute the function - fvec_t * out = new_fvec(vec->length); - aubio_filter_do_outplace (self->o, vec, out); - return PyAubio_CFvecToArray(out); + aubio_filter_do_outplace (self->o, vec, self->out); + return PyAubio_CFvecToArray(self->out); } static PyObject * -- 2.11.0