Skip to content

Commit a9e9bbf

Browse files
fengalinperexg
authored andcommitted
alsaseq: fix 'ext' buffer fill
The `GETDICTEXT` macro used to perfom one pass on the provided int list to check the actual item types brefore allocating and filling the target buffer. The python list was not read again causing the buffer to be filled with the last value read during the type check. This patch performs the type check as well as buffer fill in one go. The buffer is freed if an item is found to be of a wrong type. Fixes: #3 Signed-off-by: François Laignel <[email protected]> Signed-off-by: Jaroslav Kysela <[email protected]>
1 parent a1e64cc commit a9e9bbf

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pyalsa/alsaseq.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@
251251
int len = PyList_Size(list); \
252252
self->event->data.ext.len = len; \
253253
if (len > 0) { \
254+
self->buff = malloc(len); \
255+
if (self->buff == NULL) { \
256+
PyErr_SetString(PyExc_TypeError, \
257+
name " no memory"); \
258+
self->event->data.ext.len = 0; \
259+
return NULL; \
260+
} \
254261
int i; \
255262
long val; \
256263
for (i = 0; i < len; i++) { \
@@ -259,18 +266,12 @@
259266
PyErr_SetString(PyExc_TypeError, \
260267
name " must be a list of integers"); \
261268
self->event->data.ext.len = 0; \
262-
return NULL; \
269+
free(self->buff); \
270+
self->buff = NULL; \
271+
return NULL; \
263272
} \
264-
} \
265-
self->buff = malloc(len); \
266-
if (self->buff == NULL) { \
267-
PyErr_SetString(PyExc_TypeError, \
268-
name " no memory"); \
269-
self->event->data.ext.len = 0; \
270-
return NULL; \
271-
} \
272-
for (i = 0; i < len; i++) \
273273
self->buff[i] = val; \
274+
} \
274275
self->event->data.ext.ptr = self->buff; \
275276
} \
276277
} \

0 commit comments

Comments
 (0)