History

python/ext/py-source.c: start fixing memory leak (see #49)

Paul Brossier committed 10 years ago

Commit a28dab61 parent f2caa921 file · +19 −12Browse files

Showing the changes to python/ext (1 of 1 file). Show all

Unified · Split

python/ext/py-source.c+19−12
@@ -8,6 +8,8 @@ typedef struct · 7 unmodified lines
88 uint_t samplerate;
99 uint_t channels;
1010 uint_t hop_size;
11+ fvec_t *read_to;
12+ fmat_t *mread_to;
1113 } Py_source;
1214
1315 static char Py_source_doc[] = ""
@@ -145,10 +147,21 @@ Py_source_init (Py_source * self, PyObject * args, PyObject * kwds) · 131 unmodified lines
145147 self->channels = aubio_source_get_channels ( self->o );
146148 }
147149
150+ self->read_to = new_fvec(self->hop_size);
151+ self->mread_to = new_fmat (self->channels, self->hop_size);
152+
148153 return 0;
149154 }
150155
151−AUBIO_DEL(source)
156+static void
157+Py_source_del (Py_source *self, PyObject *unused)
158+{
159+ del_aubio_source(self->o);
160+ del_fvec(self->read_to);
161+ del_fmat(self->mread_to);
162+ self->ob_type->tp_free((PyObject *) self);
163+}
164+
152165
153166 /* function Py_source_do */
154167 static PyObject *
@@ -157,7 +170,6 @@ Py_source_do(Py_source * self, PyObject * args) · 2 unmodified lines
157170
158171
159172 /* output vectors prototypes */
160− fvec_t* read_to;
161173 uint_t read;
162174
163175
@@ -166,16 +178,14 @@ Py_source_do(Py_source * self, PyObject * args) · 2 unmodified lines
166178
167179
168180 /* creating output read_to as a new_fvec of length self->hop_size */
169− read_to = new_fvec (self->hop_size);
170181 read = 0;
171182
172183
173184 /* compute _do function */
174− aubio_source_do (self->o, read_to, &read);
185+ aubio_source_do (self->o, self->read_to, &read);
175186
176187 PyObject *outputs = PyList_New(0);
177− PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (read_to));
178− //del_fvec (read_to);
188+ PyList_Append( outputs, (PyObject *)PyAubio_CFvecToArray (self->read_to));
179189 PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
180190 return outputs;
181191 }
@@ -187,7 +197,6 @@ Py_source_do_multi(Py_source * self, PyObject * args) · 5 unmodified lines
187197
188198
189199 /* output vectors prototypes */
190− fmat_t* read_to;
191200 uint_t read;
192201
193202
@@ -195,17 +204,15 @@ Py_source_do_multi(Py_source * self, PyObject * args) · 1 unmodified line
195204
196205
197206
198− /* creating output read_to as a new_fvec of length self->hop_size */
199− read_to = new_fmat (self->channels, self->hop_size);
207+ /* creating output mread_to as a new_fvec of length self->hop_size */
200208 read = 0;
201209
202210
203211 /* compute _do function */
204− aubio_source_do_multi (self->o, read_to, &read);
212+ aubio_source_do_multi (self->o, self->mread_to, &read);
205213
206214 PyObject *outputs = PyList_New(0);
207− PyList_Append( outputs, (PyObject *)PyAubio_CFmatToArray (read_to));
208− //del_fvec (read_to);
215+ PyList_Append( outputs, (PyObject *)PyAubio_CFmatToArray (self->mread_to));
209216 PyList_Append( outputs, (PyObject *)PyInt_FromLong (read));
210217 return outputs;
211218 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t