Skip to content

Commit f68a5a3

Browse files
committed
use an automatic variable instead of allocating on the heap
1 parent 4df8b27 commit f68a5a3

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

evdev/input.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,24 +310,25 @@ get_sw_led_snd(PyObject *self, PyObject *args)
310310
max = SW_MAX;
311311
else if (evtype == EV_SND)
312312
max = SND_MAX;
313+
else
314+
return NULL;
313315

314-
char* bits = (char*) malloc(max/8);
315-
memset(bits, 0, sizeof(bits));
316+
char bytes[(max+7)/8];
317+
memset(bytes, 0, sizeof bytes);
316318

317319
if (evtype == EV_LED)
318-
ret = ioctl(fd, EVIOCGLED(sizeof(bits)), bits);
320+
ret = ioctl(fd, EVIOCGLED(sizeof(bytes)), &bytes);
319321
else if (evtype == EV_SW)
320-
ret = ioctl(fd, EVIOCGSW(sizeof(bits)), bits);
322+
ret = ioctl(fd, EVIOCGSW(sizeof(bytes)), &bytes);
321323
else if (evtype == EV_SND)
322-
ret = ioctl(fd, EVIOCGSND(sizeof(bits)), bits);
324+
ret = ioctl(fd, EVIOCGSND(sizeof(bytes)), &bytes);
323325

324326
for (i=0 ; i<max ; i++) {
325-
if (test_bit(bits, i)) {
327+
if (test_bit(bytes, i)) {
326328
PyList_Append(res, Py_BuildValue("i", i));
327329
}
328330
}
329331

330-
free(bits);
331332
return res;
332333
}
333334

0 commit comments

Comments
 (0)