ref: 7c785e6842c286b9c65e4fee8b755cfeeaefcda9
parent: de81d2bf2ae23930614aa27ef8a3cd83c3884255
author: Paul Brossier <piem@piem.org>
date: Mon Apr 18 17:14:41 EDT 2016
ext/py-filter.c: continue fixing memory leak (#49)
--- a/python/ext/py-filter.c
+++ b/python/ext/py-filter.c
@@ -5,6 +5,7 @@
PyObject_HEAD
aubio_filter_t * o;
uint_t order;
+ fvec_t *out;
} Py_filter;
static char Py_filter_doc[] = "filter object";
@@ -47,7 +48,7 @@
if (self->o == NULL) {
return -1;
}
-
+ self->out = new_fvec(Py_default_vector_length);
return 0;
}
@@ -54,6 +55,7 @@
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 @@
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 *